Skip to content

revise operator precedence grouping in gofmt #3693

@dominikh

Description

@dominikh
gofmt uses spacing to group operands/operators with the same precedence to show order
e.g. "a+b | c". At the same time, it avoids the grouping if parentheses are
being used, e.g. "(a + b) | c".

One place, where this doesn't work as expected, however, is in function calls (and by
extension type conversions). gofmt produces the following output: "foo(a+b) |
c", even though "a + b" is already grouped by parentheses. While this
might be okay generally, it produces very unreadable output when working with bit masks.
E.g. "foo(someVariable&someBitmask) | c" is hard to read and especially
hard to recognize as a bitwise operation from a distance.

My request is to either generally accept that function calls already group the operands,
so that there is no need to group them with the lack of spacing, or to add special
treating for &, &&, | and || because they do not read well without spacing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions