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(
54185418 if (for_full.label_token) |label_token| {
54195419 try astgen.checkLabelRedefinition(scope, label_token);
54205420 }
5421
54215422 // Set up variables and constants.
54225423 const is_inline = parent_gz.force_comptime or for_full.inline_token != null;
54235424 const tree = astgen.tree;
54245425 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);
54275434 const len = try parent_gz.addUnNode(.indexable_ptr_len, array_ptr, for_full.ast.cond_expr);
54285435
54295436 const index_ptr = blk: {