From 3a3704be05adcf929353e836222399885d1d99fb Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Wed, 25 Aug 2021 02:55:35 +0200 Subject: [PATCH] Don't use .none_or_ref for for(expr) We can already know whether the user want the expression to be a pointer or ref based on whether the asterisk token is used, like with if and switch. --- src/AstGen.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index 2b2bbd4f22..ae1c6be0da 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -5418,12 +5418,19 @@ fn forExpr( if (for_full.label_token) |label_token| { try astgen.checkLabelRedefinition(scope, label_token); } + // Set up variables and constants. const is_inline = parent_gz.force_comptime or for_full.inline_token != null; const tree = astgen.tree; const token_tags = tree.tokens.items(.tag); - const array_ptr = try expr(parent_gz, scope, .none_or_ref, for_full.ast.cond_expr); + const payload_is_ref = if (for_full.payload_token) |payload_token| + token_tags[payload_token] == .asterisk + else + false; + + const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none; + const array_ptr = try expr(parent_gz, scope, cond_rl, for_full.ast.cond_expr); const len = try parent_gz.addUnNode(.indexable_ptr_len, array_ptr, for_full.ast.cond_expr); const index_ptr = blk: {