Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect error messages in enum instantiation #5583

Closed
ironcev opened this issue Feb 8, 2024 · 0 comments · Fixed by #5643
Closed

Incorrect error messages in enum instantiation #5583

ironcev opened this issue Feb 8, 2024 · 0 comments · Fixed by #5643
Assignees
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@ironcev
Copy link
Member

ironcev commented Feb 8, 2024

The following example generates incorrect error messages:

script;

enum MyOption {
    Some: bool,
    None: (),
}

enum MyOtherOption {
    NoSome: bool,
    None: (),
}

main() {
    let _: MyOption = Option::Some(123);
           //                      ^^^ Mismatched types.
           // expected: bool      // WRONG: Expectation is coming from a type that is not `Option`.
           // found:    numeric.
           // help: Enum instantiator must match its declared variant type.

    let _: MyOtherOption = Option::Some(123);
           //                      ^^^^ Variant "Some" does not exist on enum "MyOtherOption"
           // WRONG: We are type-checking `Option` and `Some` do exist.

    let _: Option<u8> = Option::Some(123u64);
          //            ^^^^^^^^^^^^^^^^^^^^ Mismatched types.
          // expected: u8   // WRONG: Should be `Option<u8>`.
          // found:    u64.   // WRONG: Should be `Option<u64>`.
          // help: Variable declaration's type annotation does not match up with the assigned expression's type.

}

The reason for the first two misleading messages is taking the LHS enum as the type annotation source for the RHS without checking that it is the same enum type.

@ironcev ironcev added bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Feb 8, 2024
@ironcev ironcev self-assigned this Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant