authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-08-25 02:55:35+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-27 18:53:03-04:00
log3a3704be05adcf929353e836222399885d1d99fb
tree5ae8a603ed54f997aa7d137d92004b7bacc30804
parent311797f68619f3de66cbdecabc2af7d2022e8874

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.

1 files changed, 8 insertions(+), 1 deletions(-)

src/AstGen.zig+8-1
...@@ -5418,12 +5418,19 @@ fn forExpr(...@@ -5418,12 +5418,19 @@ fn forExpr(
5418 if (for_full.label_token) |label_token| {5418 if (for_full.label_token) |label_token| {
5419 try astgen.checkLabelRedefinition(scope, label_token);5419 try astgen.checkLabelRedefinition(scope, label_token);
5420 }5420 }
5421
5421 // Set up variables and constants.5422 // Set up variables and constants.
5422 const is_inline = parent_gz.force_comptime or for_full.inline_token != null;5423 const is_inline = parent_gz.force_comptime or for_full.inline_token != null;
5423 const tree = astgen.tree;5424 const tree = astgen.tree;
5424 const token_tags = tree.tokens.items(.tag);5425 const token_tags = tree.tokens.items(.tag);
54255426
5426 const array_ptr = try expr(parent_gz, scope, .none_or_ref, for_full.ast.cond_expr);5427 const payload_is_ref = if (for_full.payload_token) |payload_token|
5428 token_tags[payload_token] == .asterisk
5429 else
5430 false;
5431
5432 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;
5433 const array_ptr = try expr(parent_gz, scope, cond_rl, for_full.ast.cond_expr);
5427 const len = try parent_gz.addUnNode(.indexable_ptr_len, array_ptr, for_full.ast.cond_expr);5434 const len = try parent_gz.addUnNode(.indexable_ptr_len, array_ptr, for_full.ast.cond_expr);
54285435
5429 const index_ptr = blk: {5436 const index_ptr = blk: {