java overload resolution: don't cache anonymous class hierarchies (IDEA-261747)

during overload resolution it may lead to caching of a wrong hierarchy, because type of anonymous class with diamonds depends on the surrounding method call
possible optimization: reject caching only for classes with diamonds or only during overload resolution

GitOrigin-RevId: ebdb068fb9052741b8bba2b50e5faefcc541438c
This commit is contained in:
Anna Kozlova
2021-02-10 09:44:05 +01:00
committed by intellij-monorepo-bot
parent da1828b44b
commit f355f4d8cd
3 changed files with 22 additions and 0 deletions

View File

@@ -87,6 +87,9 @@ class ScopedClassHierarchy {
@NotNull
static ScopedClassHierarchy getHierarchy(@NotNull final PsiClass psiClass, @NotNull final GlobalSearchScope resolveScope) {
if (psiClass instanceof PsiAnonymousClass) {
return new ScopedClassHierarchy(psiClass, resolveScope);
}
return CachedValuesManager.getCachedValue(psiClass, () -> {
Map<GlobalSearchScope, ScopedClassHierarchy> result = ConcurrentFactoryMap.createMap(resolveScope1 -> new ScopedClassHierarchy(psiClass, resolveScope1));
return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT);

View File

@@ -0,0 +1,18 @@
interface P1<T1> { boolean test(T1 t);}
interface P2<T2> { boolean test(T2 t);}
class C {
public C(P1<String> c) { }
public C(P2<String> p) { }
}
class C1 extends C {
public C1() {
super(new P2<>() {
public boolean test(String s) {
return false;
}
});
}
}

View File

@@ -280,6 +280,7 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
public void testFixedContainingClassTypeArguments() { doTest(false);}
public void testPotentialCompatibilityWithArrayCreation() { doTest(false);}
public void testOverloadsWithOneNonCompatible() { doTest(false);}
public void testOverloadedConstructors() { doTest(false);}
public void testTwoFunctionalInterfacesWithVarargs() { doTest(false);}
public void testSecondSearchOverloadsBoxing() {
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());