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(
63336333 .instructions = .{},
63346334 .label = null,
63356335 .inlining = &inlining,
6336 .is_typeof = block.is_typeof,
63366337 .is_comptime = is_comptime_call,
63376338 .comptime_reason = comptime_reason,
63386339 .error_return_trace_index = block.error_return_trace_index,
......@@ -16532,9 +16533,6 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
1653216533 // This is only relevant at runtime.
1653316534 if (block.is_comptime or block.is_typeof) return;
1653416535
16535 // This is only relevant within functions.
16536 if (sema.func == null) return;
16537
1653816536 const save_index = inst_data.operand == .none or b: {
1653916537 const operand = try sema.resolveInst(inst_data.operand);
1654016538 const operand_ty = sema.typeOf(operand);
......@@ -27505,9 +27503,6 @@ fn analyzeLoad(
2750527503 if (try sema.pointerDeref(block, src, ptr_val, ptr_ty)) |elem_val| {
2750627504 return sema.addConstant(elem_ty, elem_val);
2750727505 }
27508 if (block.is_typeof) {
27509 return sema.addConstUndef(elem_ty);
27510 }
2751127506 }
2751227507
2751327508 return block.addTyOp(.load, elem_ty, ptr);
test/behavior/eval.zig+8
......@@ -1499,3 +1499,11 @@ test "non-optional and optional array elements concatenated" {
14991499 var index: usize = 0;
15001500 try expect(array[index].? == 'A');
15011501}
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}