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
as i32 on a payload enum value returns the aggregate: invalid LLVM, or the variant printed instead of its discriminant #1770
as i32 on an enum whose representation is an aggregate (any enum with a payload variant, with or without a representation type) is not lowered as a discriminant read. Through a parameter it happens to work; on a variant value it yields the enum aggregate itself.
enum R:
A
B(i32)
C
fn main:
print(f"{R.C as i32}")
let a = R.C as i32
print(a + 1)
Call parameter type does not match function signature!
i32 1
%R = type { i32, [4 x i8] } %17 = call { %R, i1 } @llvm.sadd.with.overflow.s_Rs(%R %.fca.1.3.insert151, i32 1)
===== INVALID LLVM FUNCTION main =====
With only the f-string line it compiles and prints C — the variant, not 2. enum Q: i32: with the same variants behaves the same. fn ra(r: R) -> i32: r as i32 returns the right tag (2; the discriminant under an explicit or @[flags] repr).
Where
MirLower.lower_cast emits RK_CAST(enum -> i32) (MIR: _3 = cast(copy _2 as ty3) with _2 = aggregate(kind=1, variant=2, fields=[])). CodegenDispatch's RK_CAST has no enum-to-integer arm: a struct-typed value falls to coerce_value_to_type (Codegen.w), whose last line returns the value unchanged — a silent fallback. MIR already has the operation: lower_enum_discriminant (RK_DISCRIMINANT, typed by enum_discriminant_type). Not yet observed in lldb.
Spec
§4.4a: "Casting: value as i32 extracts the underlying integer (identity cast)." For an enum with a payload the underlying integer is its discriminant (the tag).
Activity
MIR: `enum as number` is the discriminant read, because codegen has n…
MIR: `enum as number` is the discriminant read, because codegen has n…
MIR: `enum as number` is the discriminant read, because codegen has n…