fuzion
fuzion copied to clipboard
type argument inference may widen explicit type argument
Take this example
a(X,Y type, x X, y Y) is
say "$X $Y"
a i32 _ (option 42) (option -12) |> type_of |> say
this should produce an error since option 42 is not assignable to i32, but it runs:
> ./build/bin/fz test_infer.fz
Type of 'option i32' Type of 'option i32'
Type of 'a (option i32) (option i32)'
Apparently, the fact that Y is inferred causes the type of X to be widened.
If Y is given explicitly
a(X,Y type, x X, y Y) is
say "$X $Y"
a i32 (option i32) (option 42) (option -12) |> type_of |> say
a correct error is produced for the argument (option 42):
> ../clean/fuzion.5/build/bin/fz test_infer2.fz
/home/fridi/fuzion/fuzion/test_inferAny.fz:4:21: error 1: Incompatible types when passing argument in a call
a i32 (option i32) (option 42) (option -12) |> type_of |> say
Actual type for argument #1 'x' does not match expected type.
In call to : 'a'
expected formal type: 'i32'
actual type found : 'option i32'
assignable to : 'option i32'
for value assigned : '(option 42)'
To solve this, you could change the type of the target 'x' to 'option i32' or convert the type of the assigned value to 'i32'.
one error.