mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not create another capture when not necessary; capture should be the same when substitutor define such dependency (IDEA-57340; IDEA-5731)
This commit is contained in:
@@ -283,6 +283,14 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
|
||||
if (original == null) {
|
||||
substMap.put(param, null);
|
||||
} else {
|
||||
/*boolean alreadyFound = false;
|
||||
for (Map.Entry<PsiTypeParameter, PsiType> entry : substMap.entrySet()) {
|
||||
if (original.equals(originalSubstitutor.substitute(entry.getKey()))) {
|
||||
substMap.put(param, entry.getValue());
|
||||
alreadyFound = true;
|
||||
}
|
||||
}
|
||||
if (alreadyFound) continue;*/
|
||||
final PsiType substituted = substituteInternal(original);
|
||||
if (substituted == null) return false;
|
||||
substMap.put(param, substituted);
|
||||
@@ -297,6 +305,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
|
||||
}
|
||||
|
||||
private PsiType addBounds(PsiType substituted, final PsiTypeParameter typeParameter) {
|
||||
PsiType oldSubstituted = substituted;
|
||||
PsiElement captureContext = null;
|
||||
if (substituted instanceof PsiCapturedWildcardType) {
|
||||
final PsiCapturedWildcardType captured = (PsiCapturedWildcardType)substituted;
|
||||
@@ -331,7 +340,8 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
|
||||
|
||||
if (captureContext != null) {
|
||||
LOG.assertTrue(substituted instanceof PsiWildcardType);
|
||||
substituted = PsiCapturedWildcardType.create((PsiWildcardType)substituted, captureContext);
|
||||
substituted = oldSubstituted instanceof PsiCapturedWildcardType && substituted == ((PsiCapturedWildcardType)oldSubstituted).getWildcard()
|
||||
? oldSubstituted : PsiCapturedWildcardType.create((PsiWildcardType)substituted, captureContext);
|
||||
}
|
||||
return substituted;
|
||||
}
|
||||
|
||||
@@ -606,6 +606,19 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
PsiType paramType = paramResult.getSubstitutor().substitute(typeParameter);
|
||||
PsiType argType = argResult.getSubstitutor().substituteWithBoundsPromotion(typeParameter);
|
||||
|
||||
if (wildcardCaptured != null) {
|
||||
boolean alreadyFound = false;
|
||||
for (PsiTypeParameter typeParam : PsiUtil.typeParametersIterable(paramClass)) {
|
||||
if (typeParam != typeParameter &&
|
||||
paramType != null &&
|
||||
argResult.getSubstitutor().substituteWithBoundsPromotion(typeParam) == argType &&
|
||||
paramType.equals(paramResult.getSubstitutor().substitute(typeParam))) {
|
||||
alreadyFound = true;
|
||||
}
|
||||
}
|
||||
if (alreadyFound) continue;
|
||||
}
|
||||
|
||||
Pair<PsiType,ConstraintType> res = getSubstitutionForTypeParameterInner(paramType, argType, patternType, ConstraintType.EQUALS, depth + 1);
|
||||
|
||||
if (res != null) {
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
class A<T, S> {
|
||||
}
|
||||
|
||||
class B<L> {
|
||||
A<L, L> foo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void bar(B<?> b, A<?, ?> foo1) {
|
||||
baz(b.foo());
|
||||
A<?, ?> foo = b.foo();
|
||||
baz<error descr="'baz(A<K,K>)' in 'B' cannot be applied to '(A<capture<?>,capture<?>>)'">(foo)</error>;
|
||||
baz<error descr="'baz(A<K,K>)' in 'B' cannot be applied to '(A<capture<?>,capture<?>>)'">(foo1)</error>;
|
||||
}
|
||||
|
||||
<K> void baz(A<K, K> a) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class C<T,S>{}
|
||||
class D<T> extends C<T,T> {
|
||||
void foo(D<?> x){ bar(x); }
|
||||
<T> void bar(C<T,T> x){}
|
||||
}
|
||||
@@ -134,6 +134,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testIDEA72912() throws Exception {doTest(false);}
|
||||
public void testIllegalGenericTypeInInstanceof() throws Exception {doTest(false);}
|
||||
public void testIDEA57339() throws Exception {doTest(false);}
|
||||
public void testIDEA57340() throws Exception {doTest(false);}
|
||||
|
||||
public void testJavaUtilCollections_NoVerify() throws Exception {
|
||||
PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));
|
||||
|
||||
Reference in New Issue
Block a user