Getting super methods correctly for inheritors of Collection, etc.
This commit is contained in:
+22
-22
@@ -201,36 +201,36 @@ public class SignaturesPropagationData {
|
|||||||
List<FunctionDescriptor> superFunctions = Lists.newArrayList();
|
List<FunctionDescriptor> superFunctions = Lists.newArrayList();
|
||||||
for (HierarchicalMethodSignature superSignature : method.getPsiMethod().getHierarchicalMethodSignature().getSuperSignatures()) {
|
for (HierarchicalMethodSignature superSignature : method.getPsiMethod().getHierarchicalMethodSignature().getSuperSignatures()) {
|
||||||
PsiMethod superMethod = superSignature.getMethod();
|
PsiMethod superMethod = superSignature.getMethod();
|
||||||
|
|
||||||
|
PsiClass psiClass = superMethod.getContainingClass();
|
||||||
|
assert psiClass != null;
|
||||||
|
String classFqName = psiClass.getQualifiedName();
|
||||||
|
assert classFqName != null;
|
||||||
|
|
||||||
|
if (!JavaToKotlinClassMap.getInstance().mapPlatformClass(new FqName(classFqName)).isEmpty()) {
|
||||||
|
List<FunctionDescriptor> funsFromMap = JavaToKotlinMethodMap.INSTANCE.getFunctions(superMethod, containingClass);
|
||||||
|
superFunctions.addAll(funsFromMap);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
PsiElement superDeclaration = superMethod instanceof JetClsMethod ? ((JetClsMethod) superMethod).getOrigin() : superMethod;
|
PsiElement superDeclaration = superMethod instanceof JetClsMethod ? ((JetClsMethod) superMethod).getOrigin() : superMethod;
|
||||||
DeclarationDescriptor superFun = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, superDeclaration);
|
DeclarationDescriptor superFun = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, superDeclaration);
|
||||||
if (superFun instanceof FunctionDescriptor) {
|
if (superFun instanceof FunctionDescriptor) {
|
||||||
superFunctions.add(((FunctionDescriptor) superFun));
|
superFunctions.add(((FunctionDescriptor) superFun));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PsiClass psiClass = superMethod.getContainingClass();
|
String errorMessage = "Can't find super function for " + method.getPsiMethod() +
|
||||||
assert psiClass != null;
|
" defined in " + method.getPsiMethod().getContainingClass();
|
||||||
String fqName = psiClass.getQualifiedName();
|
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||||
assert fqName != null;
|
throw new IllegalStateException(errorMessage);
|
||||||
|
|
||||||
Collection<ClassDescriptor> platformClasses = JavaToKotlinClassMap.getInstance().mapPlatformClass(new FqName(fqName));
|
|
||||||
if (platformClasses.isEmpty()) {
|
|
||||||
String errorMessage = "Can't find super function for " + method.getPsiMethod() +
|
|
||||||
" defined in " + method.getPsiMethod().getContainingClass();
|
|
||||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
|
||||||
throw new IllegalStateException(errorMessage);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (SystemInfo.isMac) {
|
|
||||||
LOG.error("Remove duplicates from your JDK definition\n" + errorMessage);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LOG.error(errorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
List<FunctionDescriptor> funsFromMap = JavaToKotlinMethodMap.INSTANCE.getFunctions(superMethod, containingClass);
|
if (SystemInfo.isMac) {
|
||||||
superFunctions.addAll(funsFromMap);
|
LOG.error("Remove duplicates from your JDK definition\n" + errorMessage);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG.error(errorMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
|
fun foo(p: <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util.List<String><!>) {
|
||||||
|
p.iterator(); // forcing resolve of java.util.List.iterator()
|
||||||
|
|
||||||
|
ArrayList<String>().iterator(); // this provoked exception in SignaturesPropagationData
|
||||||
|
}
|
||||||
@@ -3390,6 +3390,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/regressions/OverrideResolution.kt");
|
doTest("compiler/testData/diagnostics/tests/regressions/OverrideResolution.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("resolveSubclassOfList.kt")
|
||||||
|
public void testResolveSubclassOfList() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/regressions/resolveSubclassOfList.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("SpecififcityByReceiver.kt")
|
@TestMetadata("SpecififcityByReceiver.kt")
|
||||||
public void testSpecififcityByReceiver() throws Exception {
|
public void testSpecififcityByReceiver() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/regressions/SpecififcityByReceiver.kt");
|
doTest("compiler/testData/diagnostics/tests/regressions/SpecififcityByReceiver.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user