Skip to content

Commit 3004255

Browse files
committed
Java: Minor improvement to TypeFlow for super accesses.
1 parent a7b677b commit 3004255

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,18 @@ predicate arrayInstanceOfGuarded(ArrayAccess aa, RefType t) {
440440
)
441441
}
442442

443+
/**
444+
* Holds if `t` is the type of the `this` value corresponding to the the
445+
* `SuperAccess`. As the `SuperAccess` expression has the type of the supertype,
446+
* the type `t` is a stronger type bound.
447+
*/
448+
private predicate superAccess(SuperAccess sup, RefType t) {
449+
sup.isEnclosingInstanceAccess(t)
450+
or
451+
sup.isOwnInstanceAccess() and
452+
t = sup.getEnclosingCallable().getDeclaringType()
453+
}
454+
443455
/**
444456
* Holds if `n` has type `t` and this information is discarded, such that `t`
445457
* might be a better type bound for nodes where `n` flows to. This might include
@@ -452,7 +464,8 @@ private predicate typeFlowBaseCand(TypeFlowNode n, RefType t) {
452464
downcastSuccessor(n.asExpr(), srctype) or
453465
instanceOfGuarded(n.asExpr(), srctype) or
454466
arrayInstanceOfGuarded(n.asExpr(), srctype) or
455-
n.asExpr().(FunctionalExpr).getConstructedType() = srctype
467+
n.asExpr().(FunctionalExpr).getConstructedType() = srctype or
468+
superAccess(n.asExpr(), srctype)
456469
|
457470
t = srctype.(BoundedType).getAnUltimateUpperBoundType()
458471
or

0 commit comments

Comments
 (0)