Skip to content

Commit 3e5155d

Browse files
committed
Java: Address review comments.
1 parent 92f2976 commit 3e5155d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ module MkUnification<unificationTarget/1 targetLeft, unificationTarget/1 targetR
7272
or
7373
failsUnification(t1.(Array).getComponentType(), t2.(Array).getComponentType())
7474
or
75+
// Can't unify an `extends` bound against a concrete type that doesn't
76+
// descend from that upper bound:
7577
exists(RefType upperbound, RefType other |
7678
t1.(BoundedType).getAnUltimateUpperBoundType().getSourceDeclaration() = upperbound and
7779
t2.(RefType).getSourceDeclaration() = other and
@@ -84,24 +86,28 @@ module MkUnification<unificationTarget/1 targetLeft, unificationTarget/1 targetR
8486
not other.getASourceSupertype*() = upperbound
8587
)
8688
or
89+
// Can't unify two `extends` bounds that don't intersect:
8790
exists(RefType upperbound1, RefType upperbound2 |
8891
t1.(BoundedType).getAnUltimateUpperBoundType() = upperbound1 and
8992
t2.(BoundedType).getAnUltimateUpperBoundType() = upperbound2 and
9093
notHaveIntersection(upperbound1, upperbound2)
9194
)
9295
or
96+
// Can't unify `? super X` against `Y` or `_ extends Y` where `Y` isn't an
97+
// ancestor of `X`:
9398
exists(RefType lowerbound, RefType upperbound |
9499
t1.(Wildcard).getLowerBoundType().(RefType).getSourceDeclaration() = lowerbound and
95-
getUpperBound(t2).getSourceDeclaration() = upperbound and
96-
not lowerbound instanceof BoundedType
100+
getUpperBound(t2).getSourceDeclaration() = upperbound
97101
or
98102
t2.(Wildcard).getLowerBoundType().(RefType).getSourceDeclaration() = lowerbound and
99-
getUpperBound(t1).getSourceDeclaration() = upperbound and
100-
not lowerbound instanceof BoundedType
103+
getUpperBound(t1).getSourceDeclaration() = upperbound
101104
|
105+
not lowerbound instanceof BoundedType and
102106
not lowerbound.getASourceSupertype*() = upperbound
103107
)
104108
or
109+
// Can't unify `? super T`, where `T` is a type variable `T extends S`,
110+
// with a type that doesn't intersect with `S`:
105111
exists(BoundedType lowerbound, RefType upperbound |
106112
t1.(Wildcard).getLowerBoundType() = lowerbound and
107113
getUpperBound(t2) = upperbound

0 commit comments

Comments
 (0)