Loading from Java: inner subclass of super's inner.
This commit is contained in:
+10
-2
@@ -214,8 +214,16 @@ public final class JavaFunctionResolver {
|
|||||||
FunctionDescriptor functionDescriptor
|
FunctionDescriptor functionDescriptor
|
||||||
) {
|
) {
|
||||||
for (FunctionDescriptor superFunction : superFunctions) {
|
for (FunctionDescriptor superFunction : superFunctions) {
|
||||||
TypeSubstitutor substitutor = SubstitutionUtils.buildDeepSubstitutor(
|
ClassDescriptor klass = (ClassDescriptor) functionDescriptor.getContainingDeclaration();
|
||||||
((ClassDescriptor) functionDescriptor.getContainingDeclaration()).getDefaultType());
|
List<TypeSubstitution> substitutions = Lists.newArrayList();
|
||||||
|
while (true) {
|
||||||
|
substitutions.add(SubstitutionUtils.buildDeepSubstitutor(klass.getDefaultType()).getSubstitution());
|
||||||
|
if (!klass.isInner()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
klass = (ClassDescriptor) klass.getContainingDeclaration();
|
||||||
|
}
|
||||||
|
TypeSubstitutor substitutor = TypeSubstitutor.create(substitutions.toArray(new TypeSubstitution[substitutions.size()]));
|
||||||
FunctionDescriptor superFunctionSubstituted = superFunction.substitute(substitutor);
|
FunctionDescriptor superFunctionSubstituted = superFunction.substitute(substitutor);
|
||||||
|
|
||||||
assert superFunctionSubstituted != null :
|
assert superFunctionSubstituted != null :
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public trait ReturnInnerSubclassOfSupersInner : java.lang.Object {
|
||||||
|
|
||||||
|
public open class Sub</*0*/ B> : test.ReturnInnerSubclassOfSupersInner.Super<B> {
|
||||||
|
public constructor Sub</*0*/ B>()
|
||||||
|
|
||||||
|
public/*package*/ open inner class Inner : test.ReturnInnerSubclassOfSupersInner.Super.Inner {
|
||||||
|
public/*package*/ constructor Inner()
|
||||||
|
public/*package*/ open override /*1*/ fun get() : test.ReturnInnerSubclassOfSupersInner.Sub<B>?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public open class Super</*0*/ A> : java.lang.Object {
|
||||||
|
public constructor Super</*0*/ A>()
|
||||||
|
|
||||||
|
public/*package*/ open inner class Inner : java.lang.Object {
|
||||||
|
public/*package*/ constructor Inner()
|
||||||
|
public/*package*/ open fun get() : test.ReturnInnerSubclassOfSupersInner.Super<A>?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
//Note: this test could be written in simple load java test, but KT-3128 prevents from writing Kotlin counterpart for it
|
||||||
|
public interface ReturnInnerSubclassOfSupersInner {
|
||||||
|
class Super<A> {
|
||||||
|
class Inner {
|
||||||
|
Super<A> get() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Sub<B> extends Super<B> {
|
||||||
|
class Inner extends Super<B>.Inner {
|
||||||
|
Sub<B> get() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -182,6 +182,18 @@ public final class LoadJavaCustomTest extends KotlinTestWithEnvironment {
|
|||||||
dir + "MethodTypeParameterErased.java");
|
dir + "MethodTypeParameterErased.java");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testReturnInnerSubclassOfSupersInner() throws Exception {
|
||||||
|
String dir = PATH + "/returnInnerSubclassOfSupersInner/";
|
||||||
|
doTest(dir + "ReturnInnerSubclassOfSupersInner.txt",
|
||||||
|
dir + "test/ReturnInnerSubclassOfSupersInner.java");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testReturnInnerSubclassOfSupersInnerNoCompile() throws Exception {
|
||||||
|
// Test is here because Java PSI used to have some differences when loading parallel generic hierarchies from cls and source code.
|
||||||
|
String dir = PATH + "/returnInnerSubclassOfSupersInner/";
|
||||||
|
doTestNoCompile(dir + "ReturnInnerSubclassOfSupersInner.txt", dir);
|
||||||
|
}
|
||||||
|
|
||||||
public void testReturnNotSubtype() throws Exception {
|
public void testReturnNotSubtype() throws Exception {
|
||||||
String dir = PATH + "/returnNotSubtype/";
|
String dir = PATH + "/returnNotSubtype/";
|
||||||
doTestNoCompile(dir + "ReturnNotSubtype.txt", dir);
|
doTestNoCompile(dir + "ReturnNotSubtype.txt", dir);
|
||||||
|
|||||||
Reference in New Issue
Block a user