You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Variant shorthand in an argument resolves to the wrong enum when two enums share a variant name #1712
.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
Sema: a method argument is checked against its declared parameter typ…
Sema: a method argument is checked against its declared parameter typ…
Sema: a method argument is checked against its declared parameter typ…
Sema: a method argument is checked against its declared parameter typ…
Sema: a method argument is checked against its declared parameter typ…
Sema: an if/match argument at a `&T` parameter is a join its arms dec…
Type checker: D74 entry sources and chain moves, field-view bindings (#…
Wipe's compiler issues: float joins, -> Unit bodies, method .Variant,…