Commit a760ce598c

Veikka Tuominen <git@vexu.eu>
2022-11-11 17:54:41
Sema: ensure that `!is_comptime and !is_typeof` implies `sema.func != null`
Closes #13481
1 parent d42f4ab
Changed files (2)
src
test
behavior
src/Sema.zig
@@ -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);
test/behavior/eval.zig
@@ -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);
+}