mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 08:14:48 +00:00
parent
75328e3204
commit
8503eff8c1
@ -14782,7 +14782,10 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
|
||||
return out_val->type;
|
||||
}
|
||||
|
||||
assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
|
||||
if (target_value_ptr->value.type->id != TypeTableEntryIdPointer) {
|
||||
ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target"));
|
||||
return ira->codegen->builtin_types.entry_invalid;
|
||||
}
|
||||
|
||||
TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
|
||||
ConstExprValue *pointee_val = nullptr;
|
||||
|
||||
@ -1,6 +1,21 @@
|
||||
const tests = @import("tests.zig");
|
||||
|
||||
pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
cases.add("invalid deref on switch target",
|
||||
\\comptime {
|
||||
\\ var tile = Tile.Empty;
|
||||
\\ switch (*tile) {
|
||||
\\ Tile.Empty => {},
|
||||
\\ Tile.Filled => {},
|
||||
\\ }
|
||||
\\}
|
||||
\\const Tile = enum {
|
||||
\\ Empty,
|
||||
\\ Filled,
|
||||
\\};
|
||||
,
|
||||
".tmp_source.zig:3:13: error: invalid deref on switch target");
|
||||
|
||||
cases.add("invalid field access in comptime",
|
||||
\\comptime { var x = doesnt_exist.whatever; }
|
||||
,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user