fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

Incompatible types found during type inference error not justified

Open fridis opened this issue 2 years ago • 2 comments

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
-------------------------------------------------------^


fridis avatar Jan 30 '23 10:01 fridis

The problem here is that the type inference should take the result type, option a.this.type into account as well.

fridis avatar Mar 16 '23 22:03 fridis

update:

test_this_type_in_generics is

  a ref is
    f1(b bool) option a.this => b ? a.this : nil

  say (a.f1 true)

michaellilltokiwa avatar Feb 20 '24 15:02 michaellilltokiwa