Skip to content

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

Closed

Description

@ehartford

Found under #3077. variant_type_ids is one table keyed by the bare variant name, written by every enum declaration in registration order (SemaDecl.w, the re-register loop after add_type), and a bare identifier with no demand reads it (SemaCheck.w, "Check enum variants", variant_type_ids.get(sym)). So the last enum to declare a None owns the bare name everywhere, the standard library's bodies included.

Two facets:

  1. Cross-module leak (a plain bug). With the statement-position leak of enumerate() over a List[CeremonyEdit] fails to instantiate: std/traits.w:647 None => None return type mismatch, while the same loop over a small list compiles #3077 in place, Enumerated.next's None => None arm in std/traits.w was typed CliOneLinerMode (an enum in src/main.w) and the body was refused. A module never sees an enum it does not import; the table has no module.

  2. Within one module (spec is silent). This program is refused today:

enum Mode { None, Loud }
fn main:
    let x = None
    let y: Option[i32] = x      // error: type mismatch in binding

and let x = None; x == Mode.None is true. The spec says .Member is the demanded enum's (§1.7, §9.7) and says nothing about a bare None beside a user enum's None. Law 1: a demand decides; with none, either Option's None is the prelude name the program imported (and Mode.None / .None spell the other) or the two meanings make it ambiguous and the programmer spells it. Either way the current answer, "the enum declared last", is neither.

Route: with analyze n1.w 'select:kind=ident,name~None' for the recorded type; the fix keeps one owner per visible scope (prelude + current module + imported variants via imported_variant_owners), never a foreign module's.

Activity

  1. added a commit that references this issue on Nov 8, 2026
  2. added a commit that references this issue on Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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