jfecher/ante

Repeated tuple destructuring erases generic Int trait

ehllie opened this issue · 2 comments

Running ante --show-types on the following code:

a1, a2 = (1, 2, 3, 4)
b1, b2 = a2
c1, c2 = b2

produces the output:

a1 : i32
a2 : (i32, (i32, i32))
b1 : (forall i32. i32)
b2 : (forall i32 i32. (i32, i32))
c1 : (forall a. a)
c2 : (forall a. a)

However after setting concrete int types in the tuple

a1, a2 = (1i32, 2i32, 3i32, 4i32)
b1, b2 = a2
c1, c2 = b2

the compiler is able to correctly infer variable types:

a1 : i32
a2 : (i32, (i32, i32))
b1 : i32
b2 : (i32, i32)
c1 : i32
c2 : i32

Worth noting this applies in general to any trait being solved resulting from a definition that is not generalized, with other definitions that are generalized:

trait Foo a with
    foo: unit -> a

impl Foo u64 with
    foo _ = 0

a = foo ()
b = a
c = b

Result of ante --check --show-types:

a : u64
b : (forall u64. u64)
c : (forall a. a)
foo : (forall a b. (unit -> a can b))
  given Foo a

Closing this since the specific examples given should all be fixed by c3d38d2. That commit is only a partial fix however - the bug is still present when using functions that use global variables whose type contains weak type variables. I'll open a new issue for this.