mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new inference: check provided lower bounds on type parameters, in case of fresh variables they declare the type hierarchy and otherwise constrains won't agree (IDEA-153642)
This commit is contained in:
@@ -42,24 +42,22 @@ public class JavaClassSupersImpl extends JavaClassSupers {
|
||||
@NotNull GlobalSearchScope scope,
|
||||
@NotNull PsiSubstitutor derivedSubstitutor) {
|
||||
if (InheritanceImplUtil.hasObjectQualifiedName(superClass)) return PsiSubstitutor.EMPTY;
|
||||
if (!(derivedClass instanceof PsiTypeParameter)) {
|
||||
List<PsiType> bounds = null;
|
||||
if (superClass instanceof InferenceVariable) {
|
||||
bounds = ((InferenceVariable)superClass).getBounds(InferenceBound.LOWER);
|
||||
List<PsiType> bounds = null;
|
||||
if (superClass instanceof InferenceVariable) {
|
||||
bounds = ((InferenceVariable)superClass).getBounds(InferenceBound.LOWER);
|
||||
}
|
||||
else if (superClass instanceof PsiTypeParameter) {
|
||||
final PsiType lowerBound = superClass.getUserData(InferenceSession.LOWER_BOUND);
|
||||
if (lowerBound != null) {
|
||||
bounds = Collections.singletonList(lowerBound);
|
||||
}
|
||||
else if (superClass instanceof PsiTypeParameter) {
|
||||
final PsiType lowerBound = superClass.getUserData(InferenceSession.LOWER_BOUND);
|
||||
}
|
||||
if (bounds != null) {
|
||||
for (PsiType lowerBound : bounds) {
|
||||
if (lowerBound != null) {
|
||||
bounds = Collections.singletonList(lowerBound);
|
||||
}
|
||||
}
|
||||
if (bounds != null) {
|
||||
for (PsiType lowerBound : bounds) {
|
||||
if (lowerBound != null) {
|
||||
final PsiSubstitutor substitutor = processLowerBound(lowerBound, derivedClass, scope, derivedSubstitutor);
|
||||
if (substitutor != null) {
|
||||
return substitutor;
|
||||
}
|
||||
final PsiSubstitutor substitutor = processLowerBound(lowerBound, derivedClass, scope, derivedSubstitutor);
|
||||
if (substitutor != null) {
|
||||
return substitutor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class Test<K> {
|
||||
|
||||
{
|
||||
Supplier<List<? super K>> s = Test::foo;
|
||||
}
|
||||
|
||||
static <E> List<? super E> foo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -502,6 +502,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFreshVariableLowerBoundsDuringSuptypeChecks() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user