fuzion
fuzion copied to clipboard
Incompatible types found during type inference error not justified
The following example produces an Incompatible types found during type inference for type parameters-error that is unclear (which type parameter are inferenced?) and why does the same example using if/then (#1031) work?
> cat test_this_type_in_genericsA.fz
test_this_type_in_generics is
a ref is
f1(b bool) option a.this.type is b ? a.this.type : nil
say (a.f1 true)
> ./build/bin/fz test_this_type_in_genericsA.fz
/home/fridi/fuzion/work/test_this_type_in_genericsA.fz:4:40: error 1: Incompatible types found during type inference for type parameters
f1(b bool) option a.this.type is b ? a.this.type : nil
---------------------------------------^
Types inferred for first type parameter 'T':
test_this_type_in_generics.#type<test_this_type_in_generics>.a.#type<test_this_type_in_generics.a.this.type> found at /home/fridi/fuzion/work/test_this_type_in_genericsA.fz:4:44:
f1(b bool) option a.this.type is b ? a.this.type : nil
-------------------------------------------^
nil found at /home/fridi/fuzion/work/test_this_type_in_genericsA.fz:4:56:
f1(b bool) option a.this.type is b ? a.this.type : nil
-------------------------------------------------------^
The problem here is that the type inference should take the result type, option a.this.type into account as well.
update:
test_this_type_in_generics is
a ref is
f1(b bool) option a.this => b ? a.this : nil
say (a.f1 true)