crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.22k stars 1.61k forks source link

Inconsistent behaviour regarding line break requirement in method definition #14589

Closed BlobCodes closed 1 month ago

BlobCodes commented 1 month ago

Bug Report

(Semi-)Related to #11853

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.


$ crystal -v
Crystal 1.12.1 [4cea10199] (2024-04-11)

LLVM: 15.0.7
Default target: x86_64-unknown-linux-gnu
Blacksmoke16 commented 1 month ago

Duplicate of https://github.com/crystal-lang/crystal/issues/13386