Skip to content

Commit 92f2976

Browse files
committed
Java: Improve unification check for wildcards with lower bounds.
1 parent f248c6a commit 92f2976

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

java/ql/lib/semmle/code/java/dispatch/Unification.qll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ module MkUnification<unificationTarget/1 targetLeft, unificationTarget/1 targetR
4848
arg2 = t2.getTypeArgument(pos)
4949
}
5050

51+
private RefType getUpperBound(RefType t) {
52+
if t instanceof BoundedType
53+
then result = t.(BoundedType).getAnUltimateUpperBoundType()
54+
else result = t
55+
}
56+
5157
/**
5258
* Holds if `t1` and `t2` are not unifiable.
5359
*
@@ -84,6 +90,28 @@ module MkUnification<unificationTarget/1 targetLeft, unificationTarget/1 targetR
8490
notHaveIntersection(upperbound1, upperbound2)
8591
)
8692
or
93+
exists(RefType lowerbound, RefType upperbound |
94+
t1.(Wildcard).getLowerBoundType().(RefType).getSourceDeclaration() = lowerbound and
95+
getUpperBound(t2).getSourceDeclaration() = upperbound and
96+
not lowerbound instanceof BoundedType
97+
or
98+
t2.(Wildcard).getLowerBoundType().(RefType).getSourceDeclaration() = lowerbound and
99+
getUpperBound(t1).getSourceDeclaration() = upperbound and
100+
not lowerbound instanceof BoundedType
101+
|
102+
not lowerbound.getASourceSupertype*() = upperbound
103+
)
104+
or
105+
exists(BoundedType lowerbound, RefType upperbound |
106+
t1.(Wildcard).getLowerBoundType() = lowerbound and
107+
getUpperBound(t2) = upperbound
108+
or
109+
t2.(Wildcard).getLowerBoundType() = lowerbound and
110+
getUpperBound(t1) = upperbound
111+
|
112+
notHaveIntersection(lowerbound.getUpperBoundType(), upperbound)
113+
)
114+
or
87115
not (
88116
t1 instanceof Array and t2 instanceof Array
89117
or

0 commit comments

Comments
 (0)