IR: fix switch enum variable for void enum field
parent
dab3ddab45
commit
3e25ff65c3
|
@ -8257,6 +8257,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
|
|||
return ira->codegen->builtin_types.entry_invalid;
|
||||
|
||||
TypeEnumField *field = &target_type->data.enumeration.fields[prong_val->data.x_bignum.data.x_uint];
|
||||
if (prong_value->type_entry->id == TypeTableEntryIdEnumTag) {
|
||||
field = &target_type->data.enumeration.fields[prong_val->data.x_bignum.data.x_uint];
|
||||
} else if (prong_value->type_entry->id == TypeTableEntryIdEnum) {
|
||||
field = &target_type->data.enumeration.fields[prong_val->data.x_enum.tag];
|
||||
} else {
|
||||
zig_unreachable();
|
||||
}
|
||||
|
||||
if (instr_is_comptime(target_value_ptr)) {
|
||||
zig_panic("TODO comptime switch var");
|
||||
}
|
||||
|
|
|
@ -87,6 +87,33 @@ const SwitchStatmentFoo = enum {
|
|||
};
|
||||
|
||||
|
||||
fn switchProngWithVar() {
|
||||
@setFnTest(this);
|
||||
|
||||
switchProngWithVarFn(SwitchProngWithVarEnum.One {13});
|
||||
switchProngWithVarFn(SwitchProngWithVarEnum.Two {13.0});
|
||||
switchProngWithVarFn(SwitchProngWithVarEnum.Meh);
|
||||
}
|
||||
const SwitchProngWithVarEnum = enum {
|
||||
One: i32,
|
||||
Two: f32,
|
||||
Meh,
|
||||
};
|
||||
fn switchProngWithVarFn(a: SwitchProngWithVarEnum) {
|
||||
switch(a) {
|
||||
SwitchProngWithVarEnum.One => |x| {
|
||||
if (x != 13) @unreachable();
|
||||
},
|
||||
SwitchProngWithVarEnum.Two => |x| {
|
||||
if (x != 13.0) @unreachable();
|
||||
},
|
||||
SwitchProngWithVarEnum.Meh => |x| {
|
||||
const v: void = x;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO const assert = @import("std").debug.assert;
|
||||
|
|
|
@ -13,33 +13,6 @@ const test_enum_with_members = @import("cases/enum_with_members.zig");
|
|||
const test_struct_contains_slice_of_itself = @import("cases/struct_contains_slice_of_itself.zig");
|
||||
|
||||
|
||||
fn switchProngWithVar() {
|
||||
@setFnTest(this);
|
||||
|
||||
switchProngWithVarFn(SwitchProngWithVarEnum.One {13});
|
||||
switchProngWithVarFn(SwitchProngWithVarEnum.Two {13.0});
|
||||
switchProngWithVarFn(SwitchProngWithVarEnum.Meh);
|
||||
}
|
||||
const SwitchProngWithVarEnum = enum {
|
||||
One: i32,
|
||||
Two: f32,
|
||||
Meh,
|
||||
};
|
||||
fn switchProngWithVarFn(a: SwitchProngWithVarEnum) {
|
||||
switch(a) {
|
||||
SwitchProngWithVarEnum.One => |x| {
|
||||
if (x != 13) @unreachable();
|
||||
},
|
||||
SwitchProngWithVarEnum.Two => |x| {
|
||||
if (x != 13.0) @unreachable();
|
||||
},
|
||||
SwitchProngWithVarEnum.Meh => |x| {
|
||||
const v: void = x;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn errReturnInAssignment() {
|
||||
@setFnTest(this, true);
|
||||
|
||||
|
|
Loading…
Reference in New Issue