| author | |
| committer | |
| log | 8503eff8c12697c35ab5c73d6651c4b996339706 |
| tree | 13ddf63aa1b81d4f905d80fac129866e2650cc88 |
| parent | 75328e32045d1275c03f1f37058ee0a3b775c632 |
closes #9452 files changed, 19 insertions(+), 1 deletions(-)
src/ir.cpp+4-1| ... | @@ -14782,7 +14782,10 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -14782,7 +14782,10 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 14782 | return out_val->type; | 14782 | return out_val->type; |
| 14783 | } | 14783 | } |
| 14784 | 14784 | ||
| 14785 | assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer); | 14785 | if (target_value_ptr->value.type->id != TypeTableEntryIdPointer) { |
| 14786 | ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target")); | ||
| 14787 | return ira->codegen->builtin_types.entry_invalid; | ||
| 14788 | } | ||
| 14786 | 14789 | ||
| 14787 | TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type; | 14790 | TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 14788 | ConstExprValue *pointee_val = nullptr; | 14791 | ConstExprValue *pointee_val = nullptr; |
test/compile_errors.zig+15| ... | @@ -1,6 +1,21 @@ | ... | @@ -1,6 +1,21 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | ||
| 3 | pub fn addCases(cases: &tests.CompileErrorContext) void { | 3 | pub fn addCases(cases: &tests.CompileErrorContext) void { |
| 4 | cases.add("invalid deref on switch target", | ||
| 5 | \\comptime { | ||
| 6 | \\ var tile = Tile.Empty; | ||
| 7 | \\ switch (*tile) { | ||
| 8 | \\ Tile.Empty => {}, | ||
| 9 | \\ Tile.Filled => {}, | ||
| 10 | \\ } | ||
| 11 | \\} | ||
| 12 | \\const Tile = enum { | ||
| 13 | \\ Empty, | ||
| 14 | \\ Filled, | ||
| 15 | \\}; | ||
| 16 | , | ||
| 17 | ".tmp_source.zig:3:13: error: invalid deref on switch target"); | ||
| 18 | |||
| 4 | cases.add("invalid field access in comptime", | 19 | cases.add("invalid field access in comptime", |
| 5 | \\comptime { var x = doesnt_exist.whatever; } | 20 | \\comptime { var x = doesnt_exist.whatever; } |
| 6 | , | 21 | , |