| author | |
| committer | |
| log | 3e25ff65c37739fbe095f9cdd3458d5f7c42739d |
| tree | 0f368569dd7f7f5988578f26969da9b76f7be18a |
| parent | dab3ddab4539b79b1dee4bc82f78c1b3f41ffeb2 |
3 files changed, 35 insertions(+), 27 deletions(-)
src/ir.cpp+8| ... | @@ -8257,6 +8257,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr | ... | @@ -8257,6 +8257,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr |
| 8257 | return ira->codegen->builtin_types.entry_invalid; | 8257 | return ira->codegen->builtin_types.entry_invalid; |
| 8258 | 8258 | ||
| 8259 | TypeEnumField *field = &target_type->data.enumeration.fields[prong_val->data.x_bignum.data.x_uint]; | 8259 | TypeEnumField *field = &target_type->data.enumeration.fields[prong_val->data.x_bignum.data.x_uint]; |
| 8260 | if (prong_value->type_entry->id == TypeTableEntryIdEnumTag) { | ||
| 8261 | field = &target_type->data.enumeration.fields[prong_val->data.x_bignum.data.x_uint]; | ||
| 8262 | } else if (prong_value->type_entry->id == TypeTableEntryIdEnum) { | ||
| 8263 | field = &target_type->data.enumeration.fields[prong_val->data.x_enum.tag]; | ||
| 8264 | } else { | ||
| 8265 | zig_unreachable(); | ||
| 8266 | } | ||
| 8267 | |||
| 8260 | if (instr_is_comptime(target_value_ptr)) { | 8268 | if (instr_is_comptime(target_value_ptr)) { |
| 8261 | zig_panic("TODO comptime switch var"); | 8269 | zig_panic("TODO comptime switch var"); |
| 8262 | } | 8270 | } |
test/cases3/switch.zig+27| ... | @@ -87,6 +87,33 @@ const SwitchStatmentFoo = enum { | ... | @@ -87,6 +87,33 @@ const SwitchStatmentFoo = enum { |
| 87 | }; | 87 | }; |
| 88 | 88 | ||
| 89 | 89 | ||
| 90 | fn switchProngWithVar() { | ||
| 91 | @setFnTest(this); | ||
| 92 | |||
| 93 | switchProngWithVarFn(SwitchProngWithVarEnum.One {13}); | ||
| 94 | switchProngWithVarFn(SwitchProngWithVarEnum.Two {13.0}); | ||
| 95 | switchProngWithVarFn(SwitchProngWithVarEnum.Meh); | ||
| 96 | } | ||
| 97 | const SwitchProngWithVarEnum = enum { | ||
| 98 | One: i32, | ||
| 99 | Two: f32, | ||
| 100 | Meh, | ||
| 101 | }; | ||
| 102 | fn switchProngWithVarFn(a: SwitchProngWithVarEnum) { | ||
| 103 | switch(a) { | ||
| 104 | SwitchProngWithVarEnum.One => |x| { | ||
| 105 | if (x != 13) @unreachable(); | ||
| 106 | }, | ||
| 107 | SwitchProngWithVarEnum.Two => |x| { | ||
| 108 | if (x != 13.0) @unreachable(); | ||
| 109 | }, | ||
| 110 | SwitchProngWithVarEnum.Meh => |x| { | ||
| 111 | const v: void = x; | ||
| 112 | }, | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | |||
| 90 | 117 | ||
| 91 | 118 | ||
| 92 | // TODO const assert = @import("std").debug.assert; | 119 | // TODO const assert = @import("std").debug.assert; |
test/self_hosted.zig-27| ... | @@ -13,33 +13,6 @@ const test_enum_with_members = @import("cases/enum_with_members.zig"); | ... | @@ -13,33 +13,6 @@ const test_enum_with_members = @import("cases/enum_with_members.zig"); |
| 13 | const test_struct_contains_slice_of_itself = @import("cases/struct_contains_slice_of_itself.zig"); | 13 | const test_struct_contains_slice_of_itself = @import("cases/struct_contains_slice_of_itself.zig"); |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | fn switchProngWithVar() { | ||
| 17 | @setFnTest(this); | ||
| 18 | |||
| 19 | switchProngWithVarFn(SwitchProngWithVarEnum.One {13}); | ||
| 20 | switchProngWithVarFn(SwitchProngWithVarEnum.Two {13.0}); | ||
| 21 | switchProngWithVarFn(SwitchProngWithVarEnum.Meh); | ||
| 22 | } | ||
| 23 | const SwitchProngWithVarEnum = enum { | ||
| 24 | One: i32, | ||
| 25 | Two: f32, | ||
| 26 | Meh, | ||
| 27 | }; | ||
| 28 | fn switchProngWithVarFn(a: SwitchProngWithVarEnum) { | ||
| 29 | switch(a) { | ||
| 30 | SwitchProngWithVarEnum.One => |x| { | ||
| 31 | if (x != 13) @unreachable(); | ||
| 32 | }, | ||
| 33 | SwitchProngWithVarEnum.Two => |x| { | ||
| 34 | if (x != 13.0) @unreachable(); | ||
| 35 | }, | ||
| 36 | SwitchProngWithVarEnum.Meh => |x| { | ||
| 37 | const v: void = x; | ||
| 38 | }, | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | fn errReturnInAssignment() { | 16 | fn errReturnInAssignment() { |
| 44 | @setFnTest(this, true); | 17 | @setFnTest(this, true); |
| 45 | 18 |