authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-29 17:43:07-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-29 17:43:07-07:00
log2eef83e85f1f701fb67d410d3ffc1a1b344b4c13
tree9098c9e77b7dca5d79e123997b36fcb2e174251e
parent47585cbe12251ef8b32f2e711b5f2bb48d54cbe5

AstGen: fix comptime compile error source location


1 files changed, 12 insertions(+), 5 deletions(-)

src/AstGen.zig+12-5
......@@ -830,8 +830,7 @@ pub fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) Inn
830830 .char_literal => return charLiteral(gz, scope, rl, node),
831831 .error_set_decl => return errorSetDecl(gz, scope, rl, node),
832832 .array_access => return arrayAccess(gz, scope, rl, node),
833 // 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
834 .@"comptime" => return comptimeExprFromAst(gz, scope, rl, node_datas[node].lhs),
833 .@"comptime" => return comptimeExprAst(gz, scope, rl, node),
835834 .@"switch", .switch_comma => return switchExpr(gz, scope, rl, node),
836835
837836 .@"nosuspend" => return nosuspendExpr(gz, scope, rl, node),
......@@ -1455,7 +1454,9 @@ pub fn structInitExprRlTy(
14551454 return init_inst;
14561455}
14571456
1458pub fn comptimeExpr(
1457/// This calls expr in a comptime scope, and is intended to be called as a helper function.
1458/// The one that corresponds to `comptime` expression syntax is `comptimeExprAst`.
1459fn comptimeExpr(
14591460 gz: *GenZir,
14601461 scope: *Scope,
14611462 rl: ResultLoc,
......@@ -1468,7 +1469,10 @@ pub fn comptimeExpr(
14681469 return result;
14691470}
14701471
1471pub fn comptimeExprFromAst(
1472/// This one is for an actual `comptime` syntax, and will emit a compile error if
1473/// the scope already has `force_comptime=true`.
1474/// See `comptimeExpr` for the helper function for calling expr in a comptime scope.
1475fn comptimeExprAst(
14721476 gz: *GenZir,
14731477 scope: *Scope,
14741478 rl: ResultLoc,
......@@ -1478,8 +1482,11 @@ pub fn comptimeExprFromAst(
14781482 if (gz.force_comptime) {
14791483 return astgen.failNode(node, "redundant comptime keyword in already comptime scope", .{});
14801484 }
1485 const tree = &astgen.file.tree;
1486 const node_datas = tree.nodes.items(.data);
1487 const body_node = node_datas[node].lhs;
14811488 gz.force_comptime = true;
1482 const result = try expr(gz, scope, rl, node);
1489 const result = try expr(gz, scope, rl, body_node);
14831490 gz.force_comptime = false;
14841491 return result;
14851492}