| ... | ... | @@ -247,7 +247,11 @@ pub const align_rl: ResultLoc = .{ .ty = .u16_type }; |
| 247 | 247 | pub const bool_rl: ResultLoc = .{ .ty = .bool_type }; |
| 248 | 248 | |
| 249 | 249 | pub fn typeExpr(gz: *GenZir, scope: *Scope, type_node: ast.Node.Index) InnerError!Zir.Inst.Ref { |
| 250 | | return expr(gz, scope, .{ .ty = .type_type }, type_node); |
| 250 | const prev_force_comptime = gz.force_comptime; |
| 251 | gz.force_comptime = true; |
| 252 | const e = expr(gz, scope, .{ .ty = .type_type }, type_node); |
| 253 | gz.force_comptime = prev_force_comptime; |
| 254 | return e; |
| 251 | 255 | } |
| 252 | 256 | |
| 253 | 257 | 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 |
| 821 | 825 | .char_literal => return charLiteral(gz, scope, rl, node), |
| 822 | 826 | .error_set_decl => return errorSetDecl(gz, scope, rl, node), |
| 823 | 827 | .array_access => return arrayAccess(gz, scope, rl, node), |
| 824 | | .@"comptime" => return comptimeExpr(gz, scope, rl, node_datas[node].lhs), |
| 828 | // 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 |
| 829 | .@"comptime" => return comptimeExprFromAst(gz, scope, rl, node_datas[node].lhs), |
| 825 | 830 | .@"switch", .switch_comma => return switchExpr(gz, scope, rl, node), |
| 826 | 831 | |
| 827 | 832 | .@"nosuspend" => return nosuspendExpr(gz, scope, rl, node), |
| ... | ... | @@ -1460,6 +1465,22 @@ pub fn comptimeExpr( |
| 1460 | 1465 | return result; |
| 1461 | 1466 | } |
| 1462 | 1467 | |
| 1468 | pub fn comptimeExprFromAst( |
| 1469 | gz: *GenZir, |
| 1470 | scope: *Scope, |
| 1471 | rl: ResultLoc, |
| 1472 | node: ast.Node.Index, |
| 1473 | ) InnerError!Zir.Inst.Ref { |
| 1474 | const astgen = gz.astgen; |
| 1475 | if (gz.force_comptime) { |
| 1476 | return astgen.failNode(node, "redundant comptime keyword in already comptime scope", .{}); |
| 1477 | } |
| 1478 | gz.force_comptime = true; |
| 1479 | const result = try expr(gz, scope, rl, node); |
| 1480 | gz.force_comptime = false; |
| 1481 | return result; |
| 1482 | } |
| 1483 | |
| 1463 | 1484 | fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: ast.Node.Index) InnerError!Zir.Inst.Ref { |
| 1464 | 1485 | const astgen = parent_gz.astgen; |
| 1465 | 1486 | const tree = &astgen.file.tree; |