authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-25 23:28:50+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-26 18:05:27+02:00
logfe388982462db067bdb697ec3e89c2c13ce2ffa8
treed0b4522e55999535cd5ba28c515f523cedd8a3bf
parent587ef60a28ae7c1c780e02ecf60b331ead53bc7f

Sema: pass c_import_buf to child block in more places

Closes #13651

3 files changed, 20 insertions(+), 0 deletions(-)

src/AstGen.zig+3
......@@ -7674,6 +7674,7 @@ fn typeOf(
76747674
76757675 var typeof_scope = gz.makeSubBlock(scope);
76767676 typeof_scope.force_comptime = false;
7677 typeof_scope.c_import = false;
76777678 defer typeof_scope.unstack();
76787679
76797680 const ty_expr = try reachableExpr(&typeof_scope, &typeof_scope.base, .{ .rl = .none }, args[0], node);
......@@ -8532,6 +8533,8 @@ fn cImport(
85328533 const astgen = gz.astgen;
85338534 const gpa = astgen.gpa;
85348535
8536 if (gz.c_import) return gz.astgen.failNode(node, "cannot nest @cImport", .{});
8537
85358538 var block_scope = gz.makeSubBlock(scope);
85368539 block_scope.force_comptime = true;
85378540 block_scope.c_import = true;
src/Sema.zig+2
......@@ -5105,6 +5105,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErro
51055105 .is_typeof = parent_block.is_typeof,
51065106 .want_safety = parent_block.want_safety,
51075107 .float_mode = parent_block.float_mode,
5108 .c_import_buf = parent_block.c_import_buf,
51085109 .runtime_cond = parent_block.runtime_cond,
51095110 .runtime_loop = parent_block.runtime_loop,
51105111 .runtime_index = parent_block.runtime_index,
......@@ -10266,6 +10267,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1026610267 .comptime_reason = block.comptime_reason,
1026710268 .is_typeof = block.is_typeof,
1026810269 .switch_else_err_ty = else_error_ty,
10270 .c_import_buf = block.c_import_buf,
1026910271 .runtime_cond = block.runtime_cond,
1027010272 .runtime_loop = block.runtime_loop,
1027110273 .runtime_index = block.runtime_index,
test/cases/compile_errors/cimport.zig created+15
......@@ -0,0 +1,15 @@
1const b = @cDefine("foo", "1");
2const c = @cImport({
3 _ = @TypeOf(@cDefine("foo", "1"));
4});
5const d = @cImport({
6 _ = @cImport(@cDefine("foo", "1"));
7});
8
9// error
10// backend=stage2
11// target=native
12//
13// :1:11: error: C define valid only inside C import block
14// :3:17: error: C define valid only inside C import block
15// :6:9: error: cannot nest @cImport