File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
test/query-tests/Expressions/WhitespaceContradictsPrecedence Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,16 @@ class HarmlessNestedExpr extends BinaryExpr {
6161 }
6262}
6363
64+ /**
65+ * Holds if contradicting whitespace for `binop` is unlikely to cause confusion.
66+ */
67+ predicate benignWhitespace ( BinaryExpr binop ) {
68+ // asm.js like `expr |0` binary expression.
69+ not binop .getParent ( ) instanceof BinaryExpr and
70+ binop .getOperator ( ) = "|" and
71+ binop .getRightOperand ( ) .getIntValue ( ) = 0
72+ }
73+
6474/**
6575 * Holds if `inner` is an operand of `outer`, and the relative precedence
6676 * may not be immediately clear, but is important for the semantics of
@@ -69,7 +79,8 @@ class HarmlessNestedExpr extends BinaryExpr {
6979predicate interestingNesting ( BinaryExpr inner , BinaryExpr outer ) {
7080 inner = outer .getAChildExpr ( ) and
7181 not inner instanceof AssocNestedExpr and
72- not inner instanceof HarmlessNestedExpr
82+ not inner instanceof HarmlessNestedExpr and
83+ not benignWhitespace ( outer )
7384}
7485
7586from BinaryExpr inner , BinaryExpr outer
Original file line number Diff line number Diff line change @@ -50,3 +50,6 @@ x + x >> 1
5050
5151// OK
5252x + x >> 1
53+
54+ // OK (asm.js-like)
55+ x = x - 1 | 0 ;
You can’t perform that action at this time.
0 commit comments