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

Fix variant inference for prelude types #3860

Merged
merged 4 commits into from
Nov 22, 2024

Conversation

GearsDatapacks
Copy link
Member

One small thing I noticed while playing around:

pub type Wibble {
  Wibble
  Wobble
}

pub fn main() {
  let always_wibble = Wibble
  let always_ok = Ok(Nil)

  case always_wibble {
    Wibble -> todo
  }
  // ^ This compiles fine
  case always_ok {
    Ok(Nil) -> todo
  }
  // ^ This throws an error: "Missing pattern: Error(_)"
}

It's unlikely to be much of a problem in real code, but for consistency this PR fixes it by adding the inferred_variant field to prelude values

@GearsDatapacks GearsDatapacks marked this pull request as ready for review November 21, 2024 11:41
@GearsDatapacks
Copy link
Member Author

I've had to modify several existing tests as this change made some of them obsolete, for example checking exhaustiveness errors:

case True {
  True -> todo
}
// ^ This now compiles, rendering the test useless

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you. One small comment

compiler-core/src/type_/prelude.rs Outdated Show resolved Hide resolved
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@lpil lpil merged commit 8edf4af into gleam-lang:main Nov 22, 2024
12 checks passed
@GearsDatapacks GearsDatapacks deleted the prelude-variants branch November 22, 2024 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants