I am trying some code snippets with Crystal 1.0.0 and observing this. I am not sure if this is expected behavior, if yes then any detail would be helpful to understand.
Why is 0 not getting typecasted to Float64 only while returning from a function, but assignment & as an argument is being accepted?
1 def func1 ( a : Float64 )
2 # Argument is accepted as Float64
3 a
4 end
5
6 def func2 : Float64
7 # Return type as Float64 is not accepted; Compilation error for func2
8 0
9 end
10
11 c : Float64 = 0 # Assignment is accepted as Float64
12 puts func1(0)
13 puts func2
Compilation error:
In code2.cr:6:13
6 | def func2 : Float64
^------
Error: method top-level func2 must return Float64 but it is returning Int32
My crystal version - Debian Linux
Crystal 1.0.0 [dd40a2442] (2021-03-22)
LLVM: 10.0.0
Default target: x86_64-unknown-linux-gnu