File tree Expand file tree Collapse file tree 4 files changed +22
-8
lines changed
test/query-tests/LanguageFeatures/PropertyWriteOnPrimitive Expand file tree Collapse file tree 4 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -130,13 +130,7 @@ class NumericConversion extends ImplicitConversion {
130130 or
131131 parent instanceof ArithmeticExpr and not parent instanceof AddExpr
132132 or
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- )
133+ parent .( CompoundAssignExpr ) .isNumeric ( )
140134 or
141135 parent instanceof UpdateExpr
142136 }
Original file line number Diff line number Diff line change @@ -1921,6 +1921,18 @@ private class TCompoundAssignExpr =
19211921 */
19221922class CompoundAssignExpr extends TCompoundAssignExpr , Assignment {
19231923 override string getAPrimaryQlClass ( ) { result = "CompoundAssignExpr" }
1924+
1925+ /**
1926+ * Holds if this compound assignment always returns a number value.
1927+ */
1928+ predicate isNumeric ( ) {
1929+ not (
1930+ this instanceof AssignAddExpr or
1931+ this instanceof AssignLogOrExpr or
1932+ this instanceof AssignLogAndExpr or
1933+ this instanceof AssignNullishCoalescingExpr
1934+ )
1935+ }
19241936}
19251937
19261938/**
Original file line number Diff line number Diff line change @@ -391,13 +391,15 @@ private class AnalyzedUpdateExpr extends DataFlow::AnalyzedValueNode {
391391private class AnalyzedCompoundAssignExpr extends DataFlow:: AnalyzedValueNode {
392392 override CompoundAssignExpr astNode ;
393393
394+ AnalyzedCompoundAssignExpr ( ) { astNode .isNumeric ( ) }
395+
394396 override AbstractValue getALocalValue ( ) { result = abstractValueOfType ( TTNumber ( ) ) }
395397}
396398
397399/**
398400 * Flow analysis for add-assign.
399401 */
400- private class AnalyzedAssignAddExpr extends AnalyzedCompoundAssignExpr {
402+ private class AnalyzedAssignAddExpr extends DataFlow :: AnalyzedValueNode {
401403 override AssignAddExpr astNode ;
402404
403405 override AbstractValue getALocalValue ( ) {
Original file line number Diff line number Diff line change @@ -20,4 +20,10 @@ function g(b) {
2020 return ;
2121 // OK: no types inferred for `z`, since this is dead code
2222 z . y = true ;
23+ }
24+
25+ function h ( ) {
26+ let tmp ;
27+ let obj = ( tmp ||= { } ) ;
28+ obj . p = 42 ;
2329}
You can’t perform that action at this time.
0 commit comments