I’m doing some type dispatching based on *.class overloading. I handle all nullable types in a generic function, so that I don’t have to repeat myself. This seems to work fine both for built-in types and user-defined classes, but not with String?. Take a look at the following example:
def x(t : Int32.class); puts t; end
def x(t : String.class); puts t; end
def x(t : (T | Nil).class) forall T; puts t; end
x(Int32) # => Int32
x(Int32?) # => (Int32 | Nil)
x(String) # => String
# Uncommenting the following line yields compile time error:
#x(String?)
The error is:
no overload matches ‘x’ with type (String | Nil).class
Overloads are:
- x(t : Int32.class)
- x(t : String.class)
- x(t : T | Nil.class)