mirror of
https://github.com/ziglang/zig.git
synced 2026-02-03 13:13:40 +00:00
parent
587ef60a28
commit
fe38898246
@ -7674,6 +7674,7 @@ fn typeOf(
|
||||
|
||||
var typeof_scope = gz.makeSubBlock(scope);
|
||||
typeof_scope.force_comptime = false;
|
||||
typeof_scope.c_import = false;
|
||||
defer typeof_scope.unstack();
|
||||
|
||||
const ty_expr = try reachableExpr(&typeof_scope, &typeof_scope.base, .{ .rl = .none }, args[0], node);
|
||||
@ -8532,6 +8533,8 @@ fn cImport(
|
||||
const astgen = gz.astgen;
|
||||
const gpa = astgen.gpa;
|
||||
|
||||
if (gz.c_import) return gz.astgen.failNode(node, "cannot nest @cImport", .{});
|
||||
|
||||
var block_scope = gz.makeSubBlock(scope);
|
||||
block_scope.force_comptime = true;
|
||||
block_scope.c_import = true;
|
||||
|
||||
@ -5105,6 +5105,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErro
|
||||
.is_typeof = parent_block.is_typeof,
|
||||
.want_safety = parent_block.want_safety,
|
||||
.float_mode = parent_block.float_mode,
|
||||
.c_import_buf = parent_block.c_import_buf,
|
||||
.runtime_cond = parent_block.runtime_cond,
|
||||
.runtime_loop = parent_block.runtime_loop,
|
||||
.runtime_index = parent_block.runtime_index,
|
||||
@ -10266,6 +10267,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
|
||||
.comptime_reason = block.comptime_reason,
|
||||
.is_typeof = block.is_typeof,
|
||||
.switch_else_err_ty = else_error_ty,
|
||||
.c_import_buf = block.c_import_buf,
|
||||
.runtime_cond = block.runtime_cond,
|
||||
.runtime_loop = block.runtime_loop,
|
||||
.runtime_index = block.runtime_index,
|
||||
|
||||
15
test/cases/compile_errors/cimport.zig
Normal file
15
test/cases/compile_errors/cimport.zig
Normal file
@ -0,0 +1,15 @@
|
||||
const b = @cDefine("foo", "1");
|
||||
const c = @cImport({
|
||||
_ = @TypeOf(@cDefine("foo", "1"));
|
||||
});
|
||||
const d = @cImport({
|
||||
_ = @cImport(@cDefine("foo", "1"));
|
||||
});
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :1:11: error: C define valid only inside C import block
|
||||
// :3:17: error: C define valid only inside C import block
|
||||
// :6:9: error: cannot nest @cImport
|
||||
Loading…
x
Reference in New Issue
Block a user