aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
diff options
context:
space:
mode:
authorjacob gw <jacoblevgw@gmail.com>2021-04-28 17:01:24 -0400
committerAndrew Kelley <andrew@ziglang.org>2021-04-28 19:54:04 -0400
commit2354cbafdb01d2a763b82cf03a72adef0794f187 (patch)
tree94dd0dc3b1e0be009effdbe5ac62edcc1640e660 /src/AstGen.zig
parentc90e52b74cd8f1fda78d786d38f2b8154374ce1c (diff)
downloadzig-2354cbafdb01d2a763b82cf03a72adef0794f187.tar.gz
zig-2354cbafdb01d2a763b82cf03a72adef0794f187.zip
stage2: implement #8364
Diffstat (limited to 'src/AstGen.zig')
-rw-r--r--src/AstGen.zig25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 4d7c56548d..e342ec1ac3 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -247,7 +247,11 @@ pub const align_rl: ResultLoc = .{ .ty = .u16_type };
pub const bool_rl: ResultLoc = .{ .ty = .bool_type };
pub fn typeExpr(gz: *GenZir, scope: *Scope, type_node: ast.Node.Index) InnerError!Zir.Inst.Ref {
- return expr(gz, scope, .{ .ty = .type_type }, type_node);
+ const prev_force_comptime = gz.force_comptime;
+ gz.force_comptime = true;
+ const e = expr(gz, scope, .{ .ty = .type_type }, type_node);
+ gz.force_comptime = prev_force_comptime;
+ return e;
}
fn lvalExpr(gz: *GenZir, scope: *Scope, node: ast.Node.Index) InnerError!Zir.Inst.Ref {
@@ -821,7 +825,8 @@ 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),
- .@"comptime" => return comptimeExpr(gz, scope, rl, node_datas[node].lhs),
+ // 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),
.@"switch", .switch_comma => return switchExpr(gz, scope, rl, node),
.@"nosuspend" => return nosuspendExpr(gz, scope, rl, node),
@@ -1460,6 +1465,22 @@ pub fn comptimeExpr(
return result;
}
+pub fn comptimeExprFromAst(
+ gz: *GenZir,
+ scope: *Scope,
+ rl: ResultLoc,
+ node: ast.Node.Index,
+) InnerError!Zir.Inst.Ref {
+ const astgen = gz.astgen;
+ if (gz.force_comptime) {
+ return astgen.failNode(node, "redundant comptime keyword in already comptime scope", .{});
+ }
+ gz.force_comptime = true;
+ const result = try expr(gz, scope, rl, node);
+ gz.force_comptime = false;
+ return result;
+}
+
fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: ast.Node.Index) InnerError!Zir.Inst.Ref {
const astgen = parent_gz.astgen;
const tree = &astgen.file.tree;