aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-29 17:43:07 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-29 17:43:07 -0700
commit2eef83e85f1f701fb67d410d3ffc1a1b344b4c13 (patch)
tree9098c9e77b7dca5d79e123997b36fcb2e174251e /src
parent47585cbe12251ef8b32f2e711b5f2bb48d54cbe5 (diff)
downloadzig-2eef83e85f1f701fb67d410d3ffc1a1b344b4c13.tar.gz
zig-2eef83e85f1f701fb67d410d3ffc1a1b344b4c13.zip
AstGen: fix comptime compile error source location
Diffstat (limited to 'src')
-rw-r--r--src/AstGen.zig17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 8e653d4feb..c0ee500d1a 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -830,8 +830,7 @@ pub fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) Inn
.char_literal => return charLiteral(gz, scope, rl, node),
.error_set_decl => return errorSetDecl(gz, scope, rl, node),
.array_access => return arrayAccess(gz, scope, rl, node),
- // we use comptimeExprFromAst here as it is explicitly put there by the user, `comptimeExpr` can be used by the compiler, even in a comptime scope
- .@"comptime" => return comptimeExprFromAst(gz, scope, rl, node_datas[node].lhs),
+ .@"comptime" => return comptimeExprAst(gz, scope, rl, node),
.@"switch", .switch_comma => return switchExpr(gz, scope, rl, node),
.@"nosuspend" => return nosuspendExpr(gz, scope, rl, node),
@@ -1455,7 +1454,9 @@ pub fn structInitExprRlTy(
return init_inst;
}
-pub fn comptimeExpr(
+/// This calls expr in a comptime scope, and is intended to be called as a helper function.
+/// The one that corresponds to `comptime` expression syntax is `comptimeExprAst`.
+fn comptimeExpr(
gz: *GenZir,
scope: *Scope,
rl: ResultLoc,
@@ -1468,7 +1469,10 @@ pub fn comptimeExpr(
return result;
}
-pub fn comptimeExprFromAst(
+/// This one is for an actual `comptime` syntax, and will emit a compile error if
+/// the scope already has `force_comptime=true`.
+/// See `comptimeExpr` for the helper function for calling expr in a comptime scope.
+fn comptimeExprAst(
gz: *GenZir,
scope: *Scope,
rl: ResultLoc,
@@ -1478,8 +1482,11 @@ pub fn comptimeExprFromAst(
if (gz.force_comptime) {
return astgen.failNode(node, "redundant comptime keyword in already comptime scope", .{});
}
+ const tree = &astgen.file.tree;
+ const node_datas = tree.nodes.items(.data);
+ const body_node = node_datas[node].lhs;
gz.force_comptime = true;
- const result = try expr(gz, scope, rl, node);
+ const result = try expr(gz, scope, rl, body_node);
gz.force_comptime = false;
return result;
}