mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inference: check lower bounds assignability to upper bounds
lub may break some capture invariants GitOrigin-RevId: c7857bf255c357471fd9f14fc161d2ca03769f4b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
443a6e8985
commit
78095fd61d
+9
-8
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -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> { }
|
||||
}
|
||||
+1
@@ -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(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user