aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorg-w1 <jacoblevgw@gmail.com>2020-12-26 11:28:11 -0500
committerg-w1 <jacoblevgw@gmail.com>2020-12-26 11:34:15 -0500
commitd6e9862049c069bcfcafdef3f3e7de842ba44cbd (patch)
treeb0527810c07ab7270603794e7c5d2caa07a57a8b /src
parent7f512f2236cf504775bb15002be89ecbb28a7679 (diff)
downloadzig-d6e9862049c069bcfcafdef3f3e7de842ba44cbd.tar.gz
zig-d6e9862049c069bcfcafdef3f3e7de842ba44cbd.zip
add test for @compileError in zig code, not only zir
Diffstat (limited to 'src')
-rw-r--r--src/astgen.zig11
-rw-r--r--src/zir.zig1
-rw-r--r--src/zir_sema.zig2
3 files changed, 12 insertions, 2 deletions
diff --git a/src/astgen.zig b/src/astgen.zig
index deb4eb6ae9..3db3f3654d 100644
--- a/src/astgen.zig
+++ b/src/astgen.zig
@@ -2324,6 +2324,15 @@ fn import(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*
return addZIRUnOp(mod, scope, src, .import, target);
}
+fn compileError(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst {
+ try ensureBuiltinParamCount(mod, scope, call, 1);
+ const tree = scope.tree();
+ const src = tree.token_locs[call.builtin_token].start;
+ const params = call.params();
+ const target = try expr(mod, scope, .none, params[0]);
+ return addZIRUnOp(mod, scope, src, .compileerror, target);
+}
+
fn compileLog(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst {
const tree = scope.tree();
const arena = scope.arena();
@@ -2378,6 +2387,8 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built
return rlWrap(mod, scope, rl, try addZIRNoOp(mod, scope, src, .breakpoint));
} else if (mem.eql(u8, builtin_name, "@import")) {
return rlWrap(mod, scope, rl, try import(mod, scope, call));
+ } else if (mem.eql(u8, builtin_name, "@compileError")) {
+ return compileError(mod, scope, call);
} else if (mem.eql(u8, builtin_name, "@compileLog")) {
return compileLog(mod, scope, call);
} else {
diff --git a/src/zir.zig b/src/zir.zig
index 927dfa4a21..b44d06bad5 100644
--- a/src/zir.zig
+++ b/src/zir.zig
@@ -1950,7 +1950,6 @@ const EmitZIR = struct {
.tag = Inst.CompileError.base_tag,
},
.positionals = .{
-
.msg = blk: {
const msg_str = try self.arena.allocator.dupe(u8, err_msg_list.items[0].msg);
diff --git a/src/zir_sema.zig b/src/zir_sema.zig
index cbb3dfc3fb..4f0c8c0233 100644
--- a/src/zir_sema.zig
+++ b/src/zir_sema.zig
@@ -487,7 +487,7 @@ fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export)
}
fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.CompileError) InnerError!*Inst {
- const msg = try resolveConstString(mod,scope,inst.positionals.msg);
+ const msg = try resolveConstString(mod, scope, inst.positionals.msg);
return mod.fail(scope, inst.base.src, "{}", .{msg});
}