You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have two methods, each of which have the same name and number of arguments, but are annotated with different types. Generally this works well, but I found the following issue with union types:
def do_something(value : Int32)
value + 1 # something not defined for String
end
def do_something(value : String)
value.split # something not defined for Int32
end
do_something 7.as(Int32 | String) # => 8
do_something "7".as(Int32 | String) # => ["7"]
This works as written, but changing the calls to do_something value: 7.as(Int32 | String) causes the compiler to raise an error:
no overload matches 'String#+' with type Int32
This occurs in crystal 0.22.0, and the two versions can be seen here for the working version and here for the erroring version.
Please let me know if I can provide any more information.
The text was updated successfully, but these errors were encountered:
Error in main.cr:10: instantiating 'do_something()'
do_something value: 7.as(Int32 | String) # => 8
^~~~~~~~~~~~
in main.cr:6: undefined method 'split' for Int32 (compile-time type is (Int32 | String))
puts value.split
I would've expected this to at least use the first definition (with the Int32 | String restriction), but definitely didn't expect it to attempt the second.
Shuffling the order of the definitions also had no effect.
I have two methods, each of which have the same name and number of arguments, but are annotated with different types. Generally this works well, but I found the following issue with union types:
This works as written, but changing the calls to
do_something value: 7.as(Int32 | String)
causes the compiler to raise an error:This occurs in crystal 0.22.0, and the two versions can be seen here for the working version and here for the erroring version.
Please let me know if I can provide any more information.
The text was updated successfully, but these errors were encountered: