Skip to content

Commit a760ce5

Browse files
committed
Sema: ensure that !is_comptime and !is_typeof implies sema.func != null
Closes #13481
1 parent d42f4ab commit a760ce5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Sema.zig

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1503+
test "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+
}

0 commit comments

Comments
 (0)