Fixing signature when overriding with erased signature.

EA-43482 - ISE: JavaFunctionResolver.checkFunctionsOverrideCorrectly
This commit is contained in:
Evgeny Gerashchenko
2013-02-15 19:13:05 +04:00
parent cd06bdedfe
commit 48113f036f
6 changed files with 79 additions and 0 deletions
@@ -62,6 +62,7 @@ public class SignaturesPropagationData {
private final List<String> signatureErrors = Lists.newArrayList();
private final List<FunctionDescriptor> superFunctions;
private final Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> autoTypeParameterToModified;
private final ClassDescriptor containingClass;
public SignaturesPropagationData(
@NotNull ClassDescriptor containingClass,
@@ -71,6 +72,7 @@ public class SignaturesPropagationData {
@NotNull PsiMethodWrapper method,
@NotNull BindingTrace trace
) {
this.containingClass = containingClass;
superFunctions = getSuperFunctionsForMethod(method, trace, containingClass);
autoTypeParameterToModified = SignaturesUtil.recreateTypeParametersAndReturnMapping(autoTypeParameters);
@@ -617,6 +619,37 @@ public class SignaturesPropagationData {
}
}
// Weird workaround for weird case. The sample code below is compiled by javac.
// In this case, we try to replace "Any" parameter type with "T" to fix substitution principle.
//
// public interface Super<T> {
// void foo(T t);
// }
//
// public interface Sub<T> extends Super<T> {
// void foo(Object o);
// }
List<TypeParameterDescriptor> typeParameterClassifiersFromSuper = Lists.newArrayList();
for (TypeAndVariance typeFromSuper : typesFromSuper) {
ClassifierDescriptor classifierFromSuper = typeFromSuper.type.getConstructor().getDeclarationDescriptor();
if (classifierFromSuper instanceof TypeParameterDescriptor) {
typeParameterClassifiersFromSuper.add((TypeParameterDescriptor) classifierFromSuper);
}
}
if (!typeParameterClassifiersFromSuper.isEmpty() && typeParameterClassifiersFromSuper.size() == typesFromSuper.size()) {
for (TypeParameterDescriptor typeParameter : typeParameterClassifiersFromSuper) {
if (typeParameter.getContainingDeclaration() != containingClass) {
continue;
}
return autoTypeParameterToModified.containsKey(typeParameter) ? autoTypeParameterToModified
.get(typeParameter) : typeParameter;
}
}
return classifier;
}
@@ -0,0 +1,12 @@
package test;
public interface OverrideWithErasedParameter {
public interface Super<T> {
void foo(T t);
}
public interface Sub<T> extends Super<T> {
void foo(Object o);
}
}
@@ -0,0 +1,12 @@
package test
public trait OverrideWithErasedParameter: Object {
public trait Super<T>: Object {
public fun foo(p0: T?)
}
public trait Sub<T>: Super<T> {
override fun foo(p0: T?)
}
}
@@ -0,0 +1,12 @@
package test
public trait OverrideWithErasedParameter : java.lang.Object {
public trait Sub</*0*/ T> : test.OverrideWithErasedParameter.Super<T> {
public abstract override /*1*/ fun foo(/*0*/ p0 : T?) : Unit
}
public trait Super</*0*/ T> : java.lang.Object {
public abstract fun foo(/*0*/ p0 : T?) : Unit
}
}
@@ -599,6 +599,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/NullableToNotNullKotlinSignature.java");
}
@TestMetadata("OverrideWithErasedParameter.java")
public void testOverrideWithErasedParameter() throws Exception {
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/OverrideWithErasedParameter.java");
}
@TestMetadata("ReadOnlyToMutable.java")
public void testReadOnlyToMutable() throws Exception {
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/ReadOnlyToMutable.java");
@@ -1568,6 +1568,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/kotlinSignature/propagation/parameter/NullableToNotNullKotlinSignature.kt");
}
@TestMetadata("OverrideWithErasedParameter.kt")
public void testOverrideWithErasedParameter() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/kotlinSignature/propagation/parameter/OverrideWithErasedParameter.kt");
}
@TestMetadata("ReadOnlyToMutable.kt")
public void testReadOnlyToMutable() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/kotlinSignature/propagation/parameter/ReadOnlyToMutable.kt");