Skip to content

Commit d2282fc

Browse files
authored
Merge pull request #4517 from erik-krogh/logAssign
Approved by esbena
2 parents 8b084ff + 8c8cf4f commit d2282fc

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

javascript/ql/src/Expressions/ImplicitOperandConversion.ql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,13 @@ class NumericConversion extends ImplicitConversion {
130130
or
131131
parent instanceof ArithmeticExpr and not parent instanceof AddExpr
132132
or
133-
parent instanceof CompoundAssignExpr and not parent instanceof AssignAddExpr
133+
parent instanceof CompoundAssignExpr and
134+
not (
135+
parent instanceof AssignAddExpr or
136+
parent instanceof AssignLogOrExpr or
137+
parent instanceof AssignLogAndExpr or
138+
parent instanceof AssignNullishCoalescingExpr
139+
)
134140
or
135141
parent instanceof UpdateExpr
136142
}

javascript/ql/src/semmle/javascript/Expr.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ class AssignAndExpr extends @assign_and_expr, CompoundAssignExpr { }
20532053
* x ||= y
20542054
* ```
20552055
*/
2056-
class AssignLogOrExpr extends @assignlogandexpr, CompoundAssignExpr { }
2056+
class AssignLogOrExpr extends @assignlogorexpr, CompoundAssignExpr { }
20572057

20582058
/**
20592059
* A logical-'and'-assign expression.
@@ -2064,7 +2064,7 @@ class AssignLogOrExpr extends @assignlogandexpr, CompoundAssignExpr { }
20642064
* x &&= y
20652065
* ```
20662066
*/
2067-
class AssignLogAndExpr extends @assignlogorexpr, CompoundAssignExpr { }
2067+
class AssignLogAndExpr extends @assignlogandexpr, CompoundAssignExpr { }
20682068

20692069
/**
20702070
* A 'nullish-coalescing'-assign expression.

javascript/ql/test/query-tests/Expressions/ImplicitOperandConversion/ImplicitOperandConversion.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
| tst.js:106:5:106:7 | g() | This expression will be implicitly converted from undefined to number. |
1414
| tst.js:109:13:109:15 | g() | This expression will be implicitly converted from undefined to number. |
1515
| tst.js:110:13:110:15 | g() | This expression will be implicitly converted from undefined to string. |
16+
| tst.js:117:8:117:8 | y | This expression will be implicitly converted from string to number. |
17+
| tst.js:122:10:122:10 | y | This expression will be implicitly converted from string to number. |

javascript/ql/test/query-tests/Expressions/ImplicitOperandConversion/tst.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,14 @@ function l() {
110110
var b = g() + "str";
111111
});
112112

113+
114+
function m() {
115+
var x = 19, y = "string";
116+
117+
x %= y; // NOT OK
118+
x += y; // OK
119+
x ||= y; // OK
120+
x &&= y; // OK
121+
x ??= y; // OK
122+
x >>>= y; // NOT OK
123+
}

0 commit comments

Comments
 (0)