File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed
test/query-tests/Expressions/ImplicitOperandConversion Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -162,7 +162,26 @@ abstract class NullOrUndefinedConversion extends ImplicitConversion {
162
162
class PlusConversion extends NullOrUndefinedConversion {
163
163
PlusConversion ( ) { parent instanceof AddExpr or parent instanceof AssignAddExpr }
164
164
165
- override string getConversionTarget ( ) { result = "number or string" }
165
+ override string getConversionTarget ( ) {
166
+ result = getDefiniteCousinType ( )
167
+ or
168
+ not exists ( getDefiniteCousinType ( ) ) and
169
+ result = "number or string"
170
+ }
171
+
172
+ /**
173
+ * Gets the cousin of this implicit conversion.
174
+ * E.g. if this is `a` in the expression `a + b`, then the cousin is `b`.
175
+ */
176
+ private Expr getCousin ( ) { result = parent .getAChild ( ) and not result = this .getEnclosingExpr ( ) }
177
+
178
+ /**
179
+ * Gets the unique type of the cousin expression, if that type is `string` or `number`.
180
+ */
181
+ private string getDefiniteCousinType ( ) {
182
+ result = unique( InferredType t | t = getCousin ( ) .flow ( ) .analyze ( ) .getAType ( ) ) .getTypeofTag ( ) and
183
+ result = [ "string" , "number" ]
184
+ }
166
185
}
167
186
168
187
/**
Original file line number Diff line number Diff line change 3
3
| tst.js:20:6:20:13 | 'string' | This expression will be implicitly converted from string to object. |
4
4
| tst.js:26:13:26:53 | "Settin ... o '%s'" | This expression will be implicitly converted from string to number. |
5
5
| tst.js:29:18:29:26 | !callback | This expression will be implicitly converted from boolean to object. |
6
- | tst.js:53:5:53:10 | void 0 | This expression will be implicitly converted from undefined to number or string . |
6
+ | tst.js:53:5:53:10 | void 0 | This expression will be implicitly converted from undefined to number. |
7
7
| tst.js:61:3:61:3 | x | This expression will be implicitly converted from undefined to number. |
8
8
| tst.js:67:8:67:8 | y | This expression will be implicitly converted from undefined to number. |
9
9
| tst.js:73:5:73:5 | x | This expression will be implicitly converted from undefined to number. |
10
10
| tst.js:79:19:79:22 | name | This expression will be implicitly converted from undefined to string. |
11
11
| tst.js:85:3:85:3 | x | This expression will be implicitly converted from undefined to number. |
12
12
| tst.js:100:5:100:7 | f() | This expression will be implicitly converted from undefined to number. |
13
13
| tst.js:106:5:106:7 | g() | This expression will be implicitly converted from undefined to number. |
14
+ | tst.js:109:13:109:15 | g() | This expression will be implicitly converted from undefined to number. |
15
+ | tst.js:110:13:110:15 | g() | This expression will be implicitly converted from undefined to string. |
Original file line number Diff line number Diff line change @@ -105,5 +105,8 @@ function l() {
105
105
}
106
106
g ( ) | 0 ;
107
107
g ( ) ;
108
+
109
+ var a = g ( ) + 2 ;
110
+ var b = g ( ) + "str" ;
108
111
} ) ;
109
112
You can’t perform that action at this time.
0 commit comments