From 65924d31e4ed3234303d6c6ca72cf30cda0cbaa3 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Thu, 30 Jul 2026 18:45:58 -0700 Subject: [PATCH] Fix precedence upgrade when two lower prec operators surround a higher one For example, `a | b << c | d` gives two errors: one for `a | b << c` which would have been evaluated as `a | (b << c)` in 0.16.x and one for `b << c | d` which would have been evaluated as `(b << c) | d` in 0.16.x. This would have caused the `<<` to be the operator token for a hint_operator_precedence_right and a hint_operator_precedence_left note, which the fmt implementation could not handle. --- src/fmt.zig | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/fmt.zig b/src/fmt.zig index 3e104386d51054041422e596131fdc7919087058..4646fa1a28dc0467d65fd84d086797d01f468be1 100644 --- a/src/fmt.zig +++ b/src/fmt.zig @@ -400,14 +400,21 @@ fn fmtPathFile( defer operators_to_fix.deinit(gpa); // Gather ambiguous operator precedence error tokens for quick lookup later + var remaining_errors: usize = tree.errors.len; for (tree.errors) |err| { switch (err.tag) { .hint_operator_precedence_left => { - try operators_to_fix.putNoClobber(gpa, err.token - @as(u32, @intCast(err.extra.offset)), {}); + try operators_to_fix.put(gpa, err.token - @as(u32, @intCast(err.extra.offset)), {}); + remaining_errors -= 1; }, .hint_operator_precedence_right => { - try operators_to_fix.putNoClobber(gpa, err.token, {}); + try operators_to_fix.put(gpa, err.token, {}); + remaining_errors -= 1; }, + .ambiguous_operator_precedence, + .illegal_chained_operators, + .previous_ambiguous_operator, + => remaining_errors -= 1, else => continue, } } @@ -415,7 +422,7 @@ fn fmtPathFile( if (operators_to_fix.count() == 0) break :fix; // Build a new error list without the ambiguous operator precedence errors/notes - var fixed_errors: std.ArrayList(std.zig.Ast.Error) = try .initCapacity(gpa, tree.errors.len - (operators_to_fix.count() * 3)); + var fixed_errors: std.ArrayList(std.zig.Ast.Error) = try .initCapacity(gpa, remaining_errors); for (tree.errors) |err| { switch (err.tag) { .ambiguous_operator_precedence, -- 2.54.0