fuzion
fuzion copied to clipboard
Type inference problem reported as incompatible types in assignment
In this example
test_infer_result is
x(T type, a, b T) =>
say T
y(T type, a, b ()->T) =>
say T
x 42 "bla"
y ()->42 ()->"bla"
Two errors are created as expected:
> ./build/bin/fz test_infer_result.fz
/home/fridi/fuzion/work/test_infer_result.fz:7:3: error 1: Incompatible types found during type inference for type parameters
x 42 "bla"
--^
Types inferred for first type parameter 'T':
String found at /home/fridi/fuzion/work/test_infer_result.fz:7:8:
x 42 "bla"
-------^
i32 found at /home/fridi/fuzion/work/test_infer_result.fz:7:5:
x 42 "bla"
----^
/home/fridi/fuzion/work/test_infer_result.fz:8:16: error 2: Incompatible types in assignment
y ()->42 ()->"bla"
---------------^
assignment to field : 'test_infer_result.#fun1.call.result'
expected formal type: 'i32'
actual type found : 'String'
assignable to : 'String'
for value assigned : '{
"bla"
}'
To solve this, you could change the type of the target 'test_infer_result.#fun1.call.result' to 'String' or convert the type of the assigned value to 'i32'.
2 errors.
However, the problem is the same in both cases, type inference was ambiguous, but in the second case, this was not reported, but a bug during type checking was reported. The same error (Incompatible types found during type inference for type parameters) should be produced for both calls.