Skip to content

Rust Enum in Struct in Enum causes bottom level enum constructor to change type? #901

@crides

Description

@crides

Minimum example needed to reproduce

Basically I have types in Rust like these:

#[derive(Clone, Debug, VmType, Pushable, Getable)]
enum E1 {
    S1(S),
}

#[derive(Clone, Debug, VmType, Pushable, Getable)]
struct S {
    e: E2,
}

#[derive(Clone, Debug, VmType, Pushable, Getable)]
enum E2 {
    Num(i32),
}

And if I try to initialize E1 with:

let { E1, S, E2 } = import! test
let e1 = S1 { e = Num 3 }

Then I get the following:

error: Expected the following types to be equal
Expected: | Num : Int -> E1
Found: E2
1 errors were found during unification:
Types do not match:
    Expected: Int -> E1
    Found: Int -> <opaque>
  ┌─ test:3:23
  │
3 │     let e1 = S1 { e = Num 3 }
  │
  │                       ^^^^^

So it seems like suddenly E2's constructor(s) have changed (if E2 has multiple variants they all get changed). Note that this also happens in the repl*, but (assuming test is the module containing the types) when I try :t import! test it shows all types correctly, but if I try :t let { E1 } = import! test in S1 then it also shows the wrong type.

[*] The repl included in the test repo is basically the one taken from gluon, except Color is removed and the repl is run from a provided Thread.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions