| ... | @@ -830,8 +830,7 @@ pub fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) Inn | ... | @@ -830,8 +830,7 @@ pub fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) Inn |
| 830 | .char_literal => return charLiteral(gz, scope, rl, node), | 830 | .char_literal => return charLiteral(gz, scope, rl, node), |
| 831 | .error_set_decl => return errorSetDecl(gz, scope, rl, node), | 831 | .error_set_decl => return errorSetDecl(gz, scope, rl, node), |
| 832 | .array_access => return arrayAccess(gz, scope, rl, node), | 832 | .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 | 833 | .@"comptime" => return comptimeExprAst(gz, scope, rl, node), |
| 834 | .@"comptime" => return comptimeExprFromAst(gz, scope, rl, node_datas[node].lhs), | | |
| 835 | .@"switch", .switch_comma => return switchExpr(gz, scope, rl, node), | 834 | .@"switch", .switch_comma => return switchExpr(gz, scope, rl, node), |
| 836 | | 835 | |
| 837 | .@"nosuspend" => return nosuspendExpr(gz, scope, rl, node), | 836 | .@"nosuspend" => return nosuspendExpr(gz, scope, rl, node), |
| ... | @@ -1455,7 +1454,9 @@ pub fn structInitExprRlTy( | ... | @@ -1455,7 +1454,9 @@ pub fn structInitExprRlTy( |
| 1455 | return init_inst; | 1454 | return init_inst; |
| 1456 | } | 1455 | } |
| 1457 | | 1456 | |
| 1458 | pub 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`. |
| | 1459 | fn comptimeExpr( |
| 1459 | gz: *GenZir, | 1460 | gz: *GenZir, |
| 1460 | scope: *Scope, | 1461 | scope: *Scope, |
| 1461 | rl: ResultLoc, | 1462 | rl: ResultLoc, |
| ... | @@ -1468,7 +1469,10 @@ pub fn comptimeExpr( | ... | @@ -1468,7 +1469,10 @@ pub fn comptimeExpr( |
| 1468 | return result; | 1469 | return result; |
| 1469 | } | 1470 | } |
| 1470 | | 1471 | |
| 1471 | pub 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. |
| | 1475 | fn comptimeExprAst( |
| 1472 | gz: *GenZir, | 1476 | gz: *GenZir, |
| 1473 | scope: *Scope, | 1477 | scope: *Scope, |
| 1474 | rl: ResultLoc, | 1478 | rl: ResultLoc, |
| ... | @@ -1478,8 +1482,11 @@ pub fn comptimeExprFromAst( | ... | @@ -1478,8 +1482,11 @@ pub fn comptimeExprFromAst( |
| 1478 | if (gz.force_comptime) { | 1482 | if (gz.force_comptime) { |
| 1479 | return astgen.failNode(node, "redundant comptime keyword in already comptime scope", .{}); | 1483 | return astgen.failNode(node, "redundant comptime keyword in already comptime scope", .{}); |
| 1480 | } | 1484 | } |
| | 1485 | const tree = &astgen.file.tree; |
| | 1486 | const node_datas = tree.nodes.items(.data); |
| | 1487 | const body_node = node_datas[node].lhs; |
| 1481 | gz.force_comptime = true; | 1488 | gz.force_comptime = true; |
| 1482 | const result = try expr(gz, scope, rl, node); | 1489 | const result = try expr(gz, scope, rl, body_node); |
| 1483 | gz.force_comptime = false; | 1490 | gz.force_comptime = false; |
| 1484 | return result; | 1491 | return result; |
| 1485 | } | 1492 | } |