Skip to content

Variant shorthand in an argument resolves to the wrong enum when two enums share a variant name #1712

Closed

Description

@ehartford

Summary

.Variant shorthand passed as a call argument is resolved by variant name across every enum in scope instead of against the parameter's declared type. When two enums share a variant name, the later-declared enum wins and the call fails to type-check even though the parameter type is unambiguous.

Reproduction

pub enum Kind { | Block | Boss }
impl Copy for Kind
pub enum BannerKind { | Boss | Cleared }
impl Copy for BannerKind
pub type G { n: i32 = 0 }
extend G:
    fn place(mut self: Self, x: i32, kind: Kind, elite: bool = false) -> bool:
        self.n += 1
        true
fn main:
    var g = G {}
    if g.place(1, .Boss): print("placed")
    0
$ with run p7.w
error: wrong argument type in call to 'G.place'
 --> p7.w:12:19
12 |     if g.place(1, .Boss): print("placed")
  |                   ^^^^^
  = label @12:19 argument expression '.Boss' has type BannerKind
  = note: parameter 'kind' expects Kind

Deleting BannerKind, or writing Kind.Boss, compiles.

Expected

The primer (§4, "Variant shorthand works when the expected type is known") says the parameter type is the expected type here. .Boss should resolve to Kind.Boss. The same shorthand already works in let k: Kind = .Boss, in match arms, and in return position, so it is only the call-argument path that looks up by name first.

Notes

  • with v0.15.2.1, macOS arm64.
  • Hit in withlang-dev/wipe, where the simulation has Kind.Boss/BannerKind.Boss, PickupKind.Cache/BoostSource.Cache, and PickupKind.Credits/PopupKind.Credits. Every call site had to be qualified.

Activity

  1. added 5 commits that reference this issue on Sep 27, 2026
    ec9bad2
    6472979
    b82ac4e
    6a50a40
    65d6109
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