diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-05-25 18:27:17 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-05-25 19:57:44 +0300 |
| commit | eba66f4a584bbbfed93ac4de890c8a23f245fb1f (patch) | |
| tree | 5420fa7e54db0f494155049291c3e5b934a25878 /src | |
| parent | d214b6bdf05204377d897afe3eacc0cac33c59a3 (diff) | |
| download | zig-eba66f4a584bbbfed93ac4de890c8a23f245fb1f.tar.gz zig-eba66f4a584bbbfed93ac4de890c8a23f245fb1f.zip | |
Sema: handle block.is_typeof in more places
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 340b1f9db3..2d2e7f9030 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -1513,6 +1513,7 @@ fn resolveDefinedValue( ) CompileError!?Value { if (try sema.resolveMaybeUndefVal(block, src, air_ref)) |val| { if (val.isUndef()) { + if (block.is_typeof) return null; return sema.failWithUseOfUndef(block, src); } return val; @@ -12268,6 +12269,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr .inlining = block.inlining, .is_comptime = false, .is_typeof = true, + .want_safety = false, }; defer child_block.instructions.deinit(sema.gpa); @@ -20832,7 +20834,7 @@ fn analyzeDeclVal( const decl_ref = try sema.analyzeDeclRef(decl_index); const result = try sema.analyzeLoad(block, src, decl_ref, src); if (Air.refToIndex(result)) |index| { - if (sema.air_instructions.items(.tag)[index] == .constant) { + if (sema.air_instructions.items(.tag)[index] == .constant and !block.is_typeof) { try sema.decl_val_table.put(sema.gpa, decl_index, result); } } @@ -20963,6 +20965,9 @@ fn analyzeLoad( if (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) |elem_val| { return sema.addConstant(elem_ty, elem_val); } + if (block.is_typeof) { + return sema.addConstUndef(elem_ty); + } } const valid_rt = try sema.validateRunTimeType(block, src, elem_ty, false); |
