Zig finally forces parentheses on ambiguous operator precedence after a 10-year-old proposal

Partial Operator Precedence

Zig has implemented a proposal from 2016 that requires parentheses for ambiguous operator combinations, ending years of confusion over precedence rules. The change affects only rare cases—about 353 lines in the million-line codebase—while common expressions like `x + y * z` remain unchanged. Developers can fix code manually or use `zig fmt --upgrade` to automatically insert parentheses, though manual review is recommended to catch hidden bugs.

No matter how experienced you are with Zig, it’s unlikely that you’d be able to explain the evaluation order of the following expression without looking up the precedence rules: a & b + c * d >> e | f orelse g() catch h + i == j or k and l
  1. rwoerz

    Funny that they named it "orelse" which sounds like a conditional threat to me :)

  2. nitnelave

    A bit over 10 years ago, I remember implementing partial operator precedence in Bison, for an internship. I think it was merged, but I'm not sure anyone ever used it for anything :) The age of Bison for new parsers was already mostly over

  3. raphlinus

    Worth noting, WGSL does this too, and is mostly a bit stricter than Zig: `a + b & c` and `a << b & c` are errors in WGSL but accepted by Zig. (Quick: off the top of your head, how do those parse)?

    I'm thinking of doing this for symbolasm also.

  4. v9v

    Something very similar was in Fortress, see 16.2 here https://www.ccs.neu.edu/home/samth/fortress-spec.pdf

  5. skrebbel

    I never realized that languages have so many strict precedence levels because that’s easier to implement than not having them.

    This here seems like a very good idea and I hope other languages in active development take note. And als JS’ Prettier, which actively removes parentheses like these.

More from this day

2026-11-05