Currently, the parser accepts these one-liners as valid method definitions:
def a : Int32 2 end
def a()2 end
However, removing the type restriction or braces makes the parser not accept the code anymore:
def a 2 end
# => Error: unexpected token: "2"
I think this is quite weird behavior, and probably caused by "the way the parser was built", not because this was planned.
I am not sure whether this is a language improvement discussion ("should this be allowed or not?") or a bug report (inconsistency), but I think that a line terminator (or semicolon) should either be required for both variants or none.
Also, there currently seem to be no parser specs for this style of method definition.
Bug Report
(Semi-)Related to #11853
Currently, the parser accepts these one-liners as valid method definitions:
However, removing the type restriction or braces makes the parser not accept the code anymore:
I think this is quite weird behavior, and probably caused by "the way the parser was built", not because this was planned.
I am not sure whether this is a language improvement discussion ("should this be allowed or not?") or a bug report (inconsistency), but I think that a line terminator (or semicolon) should either be required for both variants or none.
Also, there currently seem to be no parser specs for this style of method definition.