8000 pattern: don't let Not leak bindings of a failed match by javabetatester · Pull Request #1855 · dominikh/go-tools · GitHub
[go: up one dir, main page]

Skip to content

pattern: don't let Not leak bindings of a failed match - #1855

Open
javabetatester wants to merge 1 commit into
dominikh:masterfrom
javabetatester:pattern-not-bindings
Open

javabetatester wants to merge 1 commit into
dominikh:masterfrom
javabetatester:pattern-not-bindings

Conversation

@javabetatester
Copy link
Copy Markdown

Not matches its operand without a binding scope, so variables bound by a partial match that then fails stay in the matcher's state. A later use of the same variable is compared with that stale value.

(BinaryExpr (Not (BinaryExpr x "+" _)) "*" x)

does not match (a*b)*c: the inner pattern binds x to a, fails on the operator, and the outer x is then compared with a instead of binding to c.

The operand now runs in its own scope, which is dropped afterwards, as Or does for an alternative that fails.

No check uses a binding inside Not today (ST1017 is the only user and binds nothing there), so no diagnostic changes; this only removes a trap for future patterns. TestNotDoesNotBind fails without the change.

Not matched its operand without a binding scope, so variables bound
by a partial match that then failed stayed in the matcher's state.
A later use of the same variable was compared with that stale value:

    (BinaryExpr (Not (BinaryExpr x "+" _)) "*" x)

did not match (a*b)*c, because x stayed bound to a.

Run the operand in its own scope and drop it, as Or does for an
alternative that fails. No check uses a binding inside Not today, so
no diagnostic changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0