Repository navigation
Merged
Conversation
…enum that registered last The bare variant table maps a name to one enum: whichever declared it last. So `None` in a standard-library body took a user enum's `None` (#3077's symptom), and a program that imported a module declaring `enum Mode: None, Loud` had its own `let x = None` typed `Mode.None`, which a discriminant enum then converted into `Option[i32]` as `Some(0)`. Sema now keeps every enum that declares a bare variant name (variant_owner_tids), and an undemanded bare name resolves by scope: an enum declared in the current module, else the prelude's Option/Result, else the one visible enum that declares it; a demand (`.None` under a known type, an explicit variant import) decides first, as before. With one owner nothing changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3088.
The bare variant table maps a name to one enum: whichever declared it last. So
Nonein a standard-library body took a user enum'sNone(#3077's symptom), and a program that imported a module declaringenum Mode: None, Loudhad its ownlet x = NonetypedMode.None, which a discriminant enum then converted intoOption[i32]asSome(0).Sema keeps every enum that declares a bare variant name (
variant_owner_tids), and an undemanded bare name resolves by scope: an enum declared in the current module, else the prelude's Option/Result, else the one visible enum that declares it. A demand (.Noneunder a known type, an explicit variant import) decides first, as before; with one owner nothing changes. A module's own enum still wins over the prelude for its own bare names (lexical scoping; that behavior is unchanged).Fixture:
test/behavior/behav_3088_bare_none_beside_imported_enum.wwithlib/mode_with_none.w(printssomeon main,nonehere).check src/main.wclean, census clean, the compile-error and enum-related behavior fixtures pass under the dev stage1 (one dev-stage1-only artefact,err_d155, fails the same on main's stage1). Gate running; battery next.