Java: Improve unification check for wildcards with lower bounds.

This commit is contained in:
Anders Schack-Mulligen
2022-08-18 14:50:26 +02:00
parent f248c6a11e
commit 92f2976399

View File

@@ -48,6 +48,12 @@ module MkUnification<unificationTarget/1 targetLeft, unificationTarget/1 targetR
arg2 = t2.getTypeArgument(pos)
}
private RefType getUpperBound(RefType t) {
if t instanceof BoundedType
then result = t.(BoundedType).getAnUltimateUpperBoundType()
else result = t
}
/**
* Holds if `t1` and `t2` are not unifiable.
*
@@ -84,6 +90,28 @@ module MkUnification<unificationTarget/1 targetLeft, unificationTarget/1 targetR
notHaveIntersection(upperbound1, upperbound2)
)
or
exists(RefType lowerbound, RefType upperbound |
t1.(Wildcard).getLowerBoundType().(RefType).getSourceDeclaration() = lowerbound and
getUpperBound(t2).getSourceDeclaration() = upperbound and
not lowerbound instanceof BoundedType
or
t2.(Wildcard).getLowerBoundType().(RefType).getSourceDeclaration() = lowerbound and
getUpperBound(t1).getSourceDeclaration() = upperbound and
not lowerbound instanceof BoundedType
|
not lowerbound.getASourceSupertype*() = upperbound
)
or
exists(BoundedType lowerbound, RefType upperbound |
t1.(Wildcard).getLowerBoundType() = lowerbound and
getUpperBound(t2) = upperbound
or
t2.(Wildcard).getLowerBoundType() = lowerbound and
getUpperBound(t1) = upperbound
|
notHaveIntersection(lowerbound.getUpperBoundType(), upperbound)
)
or
not (
t1 instanceof Array and t2 instanceof Array
or