inference: check lower bounds assignability to upper bounds

lub may break some capture invariants

GitOrigin-RevId: c7857bf255c357471fd9f14fc161d2ca03769f4b
This commit is contained in:
Anna Kozlova
2019-05-14 11:06:24 +03:00
committed by intellij-monorepo-bot
parent 443a6e8985
commit 78095fd61d
3 changed files with 21 additions and 8 deletions
@@ -1205,17 +1205,18 @@ public class InferenceSession {
else {
for (PsiType upperType : var.getBounds(InferenceBound.UPPER)) {
if (myErrorMessages == null && isProperType(upperType)) {
String incompatibleBoundsMessage = null;
if (type != lowerBound && !TypeConversionUtil.isAssignable(upperType, type)) {
incompatibleBoundsMessage = incompatibleBoundsMessage(var, substitutor, InferenceBound.EQ, EQUALITY_CONSTRAINTS_PRESENTATION, InferenceBound.UPPER, UPPER_BOUNDS_PRESENTATION);
}
else if (type == lowerBound && !TypeConversionUtil.isAssignable(upperType, lowerBound)) {
incompatibleBoundsMessage = incompatibleBoundsMessage(var, substitutor, InferenceBound.LOWER, LOWER_BOUNDS_PRESENTATION, InferenceBound.UPPER, UPPER_BOUNDS_PRESENTATION);
}
if (incompatibleBoundsMessage != null) {
registerIncompatibleErrorMessage(incompatibleBoundsMessage);
registerIncompatibleErrorMessage(incompatibleBoundsMessage(var, substitutor, InferenceBound.EQ, EQUALITY_CONSTRAINTS_PRESENTATION, InferenceBound.UPPER, UPPER_BOUNDS_PRESENTATION));
return PsiType.NULL;
}
else if (type == lowerBound) {
for (PsiType lowerBoundConjunct : var.getBounds(InferenceBound.LOWER)) {
if (isProperType(lowerBoundConjunct) && !TypeConversionUtil.isAssignable(upperType, lowerBoundConjunct)) {
registerIncompatibleErrorMessage(incompatibleBoundsMessage(var, substitutor, InferenceBound.LOWER, LOWER_BOUNDS_PRESENTATION, InferenceBound.UPPER, UPPER_BOUNDS_PRESENTATION));
return PsiType.NULL;
}
}
}
}
}
}
@@ -0,0 +1,11 @@
class MyTest<T> {
static void m(Ref<? super String> commentRef) {
commentRef = coalesce(commentRef, commentRef);
}
static <T> T coalesce(T t1, T t2) {
return t1;
}
static class Ref<T> { }
}
@@ -1043,5 +1043,6 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
public void testNestedWildcardsWithImplicitBounds() { doTest(); }
public void testCallOnRawWithExplicitTypeArguments() { doTest(); }
public void testNoCaptureConversionDuringDetectingSupertypesDeepInHierarchy() { doTest(); }
public void testLowerBoundAssignabilityCheck() { doTest(); }
public void testIgnoreErasureForProperTypeBound() { doTest(); }
}