@@ -72,6 +72,8 @@ module MkUnification<unificationTarget/1 targetLeft, unificationTarget/1 targetR
72
72
or
73
73
failsUnification ( t1 .( Array ) .getComponentType ( ) , t2 .( Array ) .getComponentType ( ) )
74
74
or
75
+ // Can't unify an `extends` bound against a concrete type that doesn't
76
+ // descend from that upper bound:
75
77
exists ( RefType upperbound , RefType other |
76
78
t1 .( BoundedType ) .getAnUltimateUpperBoundType ( ) .getSourceDeclaration ( ) = upperbound and
77
79
t2 .( RefType ) .getSourceDeclaration ( ) = other and
@@ -84,24 +86,28 @@ module MkUnification<unificationTarget/1 targetLeft, unificationTarget/1 targetR
84
86
not other .getASourceSupertype * ( ) = upperbound
85
87
)
86
88
or
89
+ // Can't unify two `extends` bounds that don't intersect:
87
90
exists ( RefType upperbound1 , RefType upperbound2 |
88
91
t1 .( BoundedType ) .getAnUltimateUpperBoundType ( ) = upperbound1 and
89
92
t2 .( BoundedType ) .getAnUltimateUpperBoundType ( ) = upperbound2 and
90
93
notHaveIntersection ( upperbound1 , upperbound2 )
91
94
)
92
95
or
96
+ // Can't unify `? super X` against `Y` or `_ extends Y` where `Y` isn't an
97
+ // ancestor of `X`:
93
98
exists ( RefType lowerbound , RefType upperbound |
94
99
t1 .( Wildcard ) .getLowerBoundType ( ) .( RefType ) .getSourceDeclaration ( ) = lowerbound and
95
- getUpperBound ( t2 ) .getSourceDeclaration ( ) = upperbound and
96
- not lowerbound instanceof BoundedType
100
+ getUpperBound ( t2 ) .getSourceDeclaration ( ) = upperbound
97
101
or
98
102
t2 .( Wildcard ) .getLowerBoundType ( ) .( RefType ) .getSourceDeclaration ( ) = lowerbound and
99
- getUpperBound ( t1 ) .getSourceDeclaration ( ) = upperbound and
100
- not lowerbound instanceof BoundedType
103
+ getUpperBound ( t1 ) .getSourceDeclaration ( ) = upperbound
101
104
|
105
+ not lowerbound instanceof BoundedType and
102
106
not lowerbound .getASourceSupertype * ( ) = upperbound
103
107
)
104
108
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`:
105
111
exists ( BoundedType lowerbound , RefType upperbound |
106
112
t1 .( Wildcard ) .getLowerBoundType ( ) = lowerbound and
107
113
getUpperBound ( t2 ) = upperbound
0 commit comments