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

Closes #13481
This commit is contained in:
Veikka Tuominen 2022-11-11 18:54:41 +02:00
parent d42f4abb9d
commit a760ce598c
2 changed files with 9 additions and 6 deletions

View File

@ -6333,6 +6333,7 @@ fn analyzeCall(
.instructions = .{},
.label = null,
.inlining = &inlining,
.is_typeof = block.is_typeof,
.is_comptime = is_comptime_call,
.comptime_reason = comptime_reason,
.error_return_trace_index = block.error_return_trace_index,
@ -16532,9 +16533,6 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
// This is only relevant at runtime.
if (block.is_comptime or block.is_typeof) return;
// This is only relevant within functions.
if (sema.func == null) return;
const save_index = inst_data.operand == .none or b: {
const operand = try sema.resolveInst(inst_data.operand);
const operand_ty = sema.typeOf(operand);
@ -27505,9 +27503,6 @@ fn analyzeLoad(
if (try sema.pointerDeref(block, src, ptr_val, ptr_ty)) |elem_val| {
return sema.addConstant(elem_ty, elem_val);
}
if (block.is_typeof) {
return sema.addConstUndef(elem_ty);
}
}
return block.addTyOp(.load, elem_ty, ptr);

View File

@ -1499,3 +1499,11 @@ test "non-optional and optional array elements concatenated" {
var index: usize = 0;
try expect(array[index].? == 'A');
}
test "inline call in @TypeOf inherits is_inline property" {
const S = struct {
inline fn doNothing() void {}
const T = @TypeOf(doNothing());
};
try expect(S.T == void);
}