Do you mean that line 5 of your code (p! test(123_i32)) should cause a compilation error because you’re passing an Int32 literal into a method that only takes a Float64 argument?
I’m asking because it seems like people think you mean that line 5 (above) is working correctly and line 8 (p! test(x)) should also work. Clarifying what you expect to happen would help us help you.
Yes, I actually mean line 5 should throw a compilation error, like line 8 does.
(or, at least, both syntax should have same behavior, I think)
Another example of oddity :
class Test
def initialize(@v : Float64)
end
end
Test.new(2)
compiles, but
class Test
getter v : Float64
def initialize(@v)
end
end
Test.new(2)
I don’t think it’s documented but it’s a language feature. Literals can be automatically casted to an argument with a type restriction as long as the value fits in the target type. Only if there’s a type restriction.