authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-11 18:54:41+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-12 15:41:29+02:00
loga760ce598c7656f7582d8305582e374af68254d9
tree71c72be4fd51f4e3e9d911bba7cab51431baaa51
parentd42f4abb9dc906ef20b622656c7672cb7df02096

Sema: ensure that `!is_comptime and !is_typeof` implies `sema.func != null`

Closes #13481

2 files changed, 9 insertions(+), 6 deletions(-)

src/Sema.zig+1-6
...@@ -6333,6 +6333,7 @@ fn analyzeCall(...@@ -6333,6 +6333,7 @@ fn analyzeCall(
6333 .instructions = .{},6333 .instructions = .{},
6334 .label = null,6334 .label = null,
6335 .inlining = &inlining,6335 .inlining = &inlining,
6336 .is_typeof = block.is_typeof,
6336 .is_comptime = is_comptime_call,6337 .is_comptime = is_comptime_call,
6337 .comptime_reason = comptime_reason,6338 .comptime_reason = comptime_reason,
6338 .error_return_trace_index = block.error_return_trace_index,6339 .error_return_trace_index = block.error_return_trace_index,
...@@ -16532,9 +16533,6 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -16532,9 +16533,6 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
16532 // This is only relevant at runtime.16533 // This is only relevant at runtime.
16533 if (block.is_comptime or block.is_typeof) return;16534 if (block.is_comptime or block.is_typeof) return;
1653416535
16535 // This is only relevant within functions.
16536 if (sema.func == null) return;
16537
16538 const save_index = inst_data.operand == .none or b: {16536 const save_index = inst_data.operand == .none or b: {
16539 const operand = try sema.resolveInst(inst_data.operand);16537 const operand = try sema.resolveInst(inst_data.operand);
16540 const operand_ty = sema.typeOf(operand);16538 const operand_ty = sema.typeOf(operand);
...@@ -27505,9 +27503,6 @@ fn analyzeLoad(...@@ -27505,9 +27503,6 @@ fn analyzeLoad(
27505 if (try sema.pointerDeref(block, src, ptr_val, ptr_ty)) |elem_val| {27503 if (try sema.pointerDeref(block, src, ptr_val, ptr_ty)) |elem_val| {
27506 return sema.addConstant(elem_ty, elem_val);27504 return sema.addConstant(elem_ty, elem_val);
27507 }27505 }
27508 if (block.is_typeof) {
27509 return sema.addConstUndef(elem_ty);
27510 }
27511 }27506 }
2751227507
27513 return block.addTyOp(.load, elem_ty, ptr);27508 return block.addTyOp(.load, elem_ty, ptr);
test/behavior/eval.zig+8
...@@ -1499,3 +1499,11 @@ test "non-optional and optional array elements concatenated" {...@@ -1499,3 +1499,11 @@ test "non-optional and optional array elements concatenated" {
1499 var index: usize = 0;1499 var index: usize = 0;
1500 try expect(array[index].? == 'A');1500 try expect(array[index].? == 'A');
1501}1501}
1502
1503test "inline call in @TypeOf inherits is_inline property" {
1504 const S = struct {
1505 inline fn doNothing() void {}
1506 const T = @TypeOf(doNothing());
1507 };
1508 try expect(S.T == void);
1509}