Skip to content

#3088: an undemanded bare variant name resolves by scope, not by the enum that registered last - #3098

Merged
ehartford merged 1 commit into
mainfrom
i3088
Nov 8, 2026
Merged

ehartford merged 1 commit into
mainfrom
i3088

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #3088.

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 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. 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.w with lib/mode_with_none.w (prints some on main, none here). check src/main.w clean, 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.

…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.
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.

An undemanded bare None resolves to whichever enum last declared a None variant, across modules

1 participant