Skip to content

Commit eb67ea3

Browse files
committed
Revert "JS: Also use contextual types directly for underlying types"
This reverts commit 385e663.
1 parent 3d87d19 commit eb67ea3

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

javascript/ql/lib/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,7 @@ module DataFlow {
229229
predicate hasUnderlyingType(string globalName) {
230230
Stages::TypeTracking::ref() and
231231
exists(NameResolution::Node type |
232-
TypeResolution::valueHasType(this.getNameResolutionNode(), type)
233-
or
234-
TypeResolution::valueHasContextualType(this.getNameResolutionNode(), type)
235-
|
232+
TypeResolution::valueHasType(this.getNameResolutionNode(), type) and
236233
UnderlyingTypes::nodeHasUnderlyingType(type, "global", globalName)
237234
)
238235
}
@@ -246,10 +243,7 @@ module DataFlow {
246243
Stages::TypeTracking::ref() and
247244
moduleName != "global" and
248245
exists(NameResolution::Node type |
249-
TypeResolution::valueHasType(this.getNameResolutionNode(), type)
250-
or
251-
TypeResolution::valueHasContextualType(this.getNameResolutionNode(), type)
252-
|
246+
TypeResolution::valueHasType(this.getNameResolutionNode(), type) and
253247
UnderlyingTypes::nodeHasUnderlyingType(type, moduleName, typeName)
254248
)
255249
}

javascript/ql/lib/semmle/javascript/internal/TypeResolution.qll

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,11 @@ module TypeResolution {
114114
)
115115
}
116116

117-
predicate valueHasContextualType(Node value, Node type) {
117+
private predicate contextualType(Node value, Node contextualType) {
118118
exists(InvokeExpr call, Function target, int i |
119119
callTarget(call, target) and
120120
value = call.getArgument(i) and
121-
type = target.getParameter(i).getTypeAnnotation()
122-
)
123-
or
124-
exists(VariableDeclarator decl |
125-
value = decl.getInit() and
126-
type = decl.getTypeAnnotation()
127-
)
128-
or
129-
exists(Function functionValue, Function functionType |
130-
valueHasContextualType(functionValue, trackFunctionType(functionType)) and
131-
value = functionValue.getAReturnedExpr() and
132-
type = functionType.getReturnTypeAnnotation()
121+
contextualType = target.getParameter(i).getTypeAnnotation()
133122
)
134123
}
135124

@@ -165,10 +154,10 @@ module TypeResolution {
165154
or
166155
// Contextual typing for parameters
167156
exists(Function lambda, Function functionType, int i |
168-
valueHasContextualType(lambda, trackFunctionType(functionType))
157+
contextualType(lambda, trackFunctionType(functionType))
169158
or
170159
exists(InterfaceDefinition interface |
171-
valueHasContextualType(lambda, trackType(interface)) and
160+
contextualType(lambda, trackType(interface)) and
172161
functionType = interface.getACallSignature().getBody()
173162
)
174163
|

0 commit comments

Comments
 (0)