| author | |
| committer | |
| log | fe388982462db067bdb697ec3e89c2c13ce2ffa8 |
| tree | d0b4522e55999535cd5ba28c515f523cedd8a3bf |
| parent | 587ef60a28ae7c1c780e02ecf60b331ead53bc7f |
Closes #136513 files changed, 20 insertions(+), 0 deletions(-)
src/AstGen.zig+3| ... | ... | @@ -7674,6 +7674,7 @@ fn typeOf( |
| 7674 | 7674 | |
| 7675 | 7675 | var typeof_scope = gz.makeSubBlock(scope); |
| 7676 | 7676 | typeof_scope.force_comptime = false; |
| 7677 | typeof_scope.c_import = false; | |
| 7677 | 7678 | defer typeof_scope.unstack(); |
| 7678 | 7679 | |
| 7679 | 7680 | const ty_expr = try reachableExpr(&typeof_scope, &typeof_scope.base, .{ .rl = .none }, args[0], node); |
| ... | ... | @@ -8532,6 +8533,8 @@ fn cImport( |
| 8532 | 8533 | const astgen = gz.astgen; |
| 8533 | 8534 | const gpa = astgen.gpa; |
| 8534 | 8535 | |
| 8536 | if (gz.c_import) return gz.astgen.failNode(node, "cannot nest @cImport", .{}); | |
| 8537 | ||
| 8535 | 8538 | var block_scope = gz.makeSubBlock(scope); |
| 8536 | 8539 | block_scope.force_comptime = true; |
| 8537 | 8540 | 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 |
| 5105 | 5105 | .is_typeof = parent_block.is_typeof, |
| 5106 | 5106 | .want_safety = parent_block.want_safety, |
| 5107 | 5107 | .float_mode = parent_block.float_mode, |
| 5108 | .c_import_buf = parent_block.c_import_buf, | |
| 5108 | 5109 | .runtime_cond = parent_block.runtime_cond, |
| 5109 | 5110 | .runtime_loop = parent_block.runtime_loop, |
| 5110 | 5111 | .runtime_index = parent_block.runtime_index, |
| ... | ... | @@ -10266,6 +10267,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10266 | 10267 | .comptime_reason = block.comptime_reason, |
| 10267 | 10268 | .is_typeof = block.is_typeof, |
| 10268 | 10269 | .switch_else_err_ty = else_error_ty, |
| 10270 | .c_import_buf = block.c_import_buf, | |
| 10269 | 10271 | .runtime_cond = block.runtime_cond, |
| 10270 | 10272 | .runtime_loop = block.runtime_loop, |
| 10271 | 10273 | .runtime_index = block.runtime_index, |
test/cases/compile_errors/cimport.zig created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | const b = @cDefine("foo", "1"); | |
| 2 | const c = @cImport({ | |
| 3 | _ = @TypeOf(@cDefine("foo", "1")); | |
| 4 | }); | |
| 5 | const 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 |