crystal-lang / crystal

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

`.class?` is not allowed in type names #11071

Open HertzDevil opened 3 years ago

HertzDevil commented 3 years ago

To my surprise, this fails to compile unless Int.class is parenthesized:

x : Int.class? # Error: expecting identifier 'class', not 'class?'
x = Int32

def foo(x : Int.class? = nil) # Error: expecting identifier 'class', not 'class?'
end

I would expect it to be parsed as Int.class | ::Nil instead.

This only goes for the type grammar, .class? should always be a regular method in normal code (which is already the case for Crystal::Type inside the compiler).

straight-shoota commented 3 years ago

I'm not sure about this. It seems very confusing to have different rules for identifiers in the type grammar.