Skip to content

cmd/dist: inverted precedence for && and || in exprParser #79185

Description

@dmitshur

cmd/dist has a small //go:build constraint parser and evaluator for the needs of bootstrapping. Back when it was added (CL 359314, CC @rsc), go/build/constraint couldn't be used because cmd/dist needed to be able to be built with much older Go releases, so an implementation was added.

@cuiweixie noticed and reported that the precedence && and || appeared wrong in a golang-dev message at https://groups.google.com/g/golang-dev/c/0k7jlbEV29o/m/3cfUZHrpCAAJ, causing gccgo && gc || gc to evaluate to false (given gc is set, gccgo is not set), though it should be true.

It can be fixed with:

-		{tok: "&&", prec: 1, infix: func(x, y val) val { return x && y }},
-		{tok: "||", prec: 2, infix: func(x, y val) val { return x || y }},
+		{tok: "||", prec: 1, infix: func(x, y val) val { return x || y }},
+		{tok: "&&", prec: 2, infix: func(x, y val) val { return x && y }},

Though it's also possible to start using go/build/constraint now and delete the parser copy. A stack ending with CL 773823 does that.

CC @cuiweixie, @adonovan.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions