KT-3702: Inner class constructor cannot be invoked in override function with receiver

KT-3532: NoSuchMethodError when constructing Java inner class
KT-3847: Class is not recognized as inner when loaded from binaries

 #KT-3702 Fixed
 #KT-3532 Fixed
 #KT-3847 Fixed
This commit is contained in:
Mikhael Bogdanov
2013-06-24 11:21:23 +04:00
parent 8e45bb7657
commit 8a4b01d9c6
9 changed files with 63 additions and 3 deletions
@@ -295,4 +295,21 @@ public class CodegenUtil {
// If you try to remove it, run tests on Windows.
return FileUtil.toSystemDependentName(file.getVirtualFile().getPath()).hashCode();
}
@Nullable
public static ClassDescriptor getExpectedThisObjectForConstructorCall(
@NotNull ConstructorDescriptor descriptor,
@Nullable CalculatedClosure closure
) {
//for compilation against sources
if (closure != null) {
return closure.getCaptureThis();
}
//for compilation against binaries
//TODO: It's best to use this code also for compilation against sources
// but sometimes structures that have expectedThisObject (bug?) mapped to static classes
ReceiverParameterDescriptor expectedThisObject = descriptor.getExpectedThisObject();
return expectedThisObject != null ? (ClassDescriptor) expectedThisObject.getContainingDeclaration() : null;
}
}
@@ -3255,7 +3255,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
ConstructorDescriptor constructorDescriptor = (ConstructorDescriptor) resolvedCall.getResultingDescriptor();
MutableClosure closure = bindingContext.get(CLOSURE, constructorDescriptor.getContainingDeclaration());
if (receiver.type.getSort() != Type.VOID && (closure == null || closure.getCaptureThis() == null)) {
ClassDescriptor descriptor = getExpectedThisObjectForConstructorCall(constructorDescriptor, closure);
if (receiver.type.getSort() != Type.VOID && descriptor == null) {
v.pop();
}
@@ -838,7 +838,7 @@ public class JetTypeMapper extends BindingTraceAware {
signatureWriter.writeParametersStart();
ClassDescriptor containingDeclaration = descriptor.getContainingDeclaration();
ClassDescriptor captureThis = closure != null ? closure.getCaptureThis() : null;
ClassDescriptor captureThis = getExpectedThisObjectForConstructorCall(descriptor, closure);
if (captureThis != null) {
signatureWriter.writeParameterType(JvmMethodParameterKind.OUTER);
mapType(captureThis.getDefaultType(), signatureWriter, JetTypeMapperMode.VALUE);
@@ -0,0 +1,3 @@
public class kt3532 {
public class Inner { }
}
@@ -0,0 +1,4 @@
fun box(): String {
kt3532().Inner()
return "OK"
}
@@ -0,0 +1,6 @@
//test for KT-3702 Inner class constructor cannot be invoked in override function with receiver
package second
public class Outer() {
inner class Inner(test: String)
}
@@ -0,0 +1,10 @@
//test for KT-3702 Inner class constructor cannot be invoked in override function with receiver
import second.Outer
fun Outer.testExt() {
Inner("test")
}
fun main(args: Array<String>) {
Outer().testExt()
}
@@ -31,7 +31,7 @@ import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/codegen/boxWithJava")
@InnerTestClasses({BlackBoxWithJavaCodegenTestGenerated.Annotations.class, BlackBoxWithJavaCodegenTestGenerated.CallableReference.class, BlackBoxWithJavaCodegenTestGenerated.Enum.class, BlackBoxWithJavaCodegenTestGenerated.Functions.class, BlackBoxWithJavaCodegenTestGenerated.Property.class, BlackBoxWithJavaCodegenTestGenerated.Sam.class, BlackBoxWithJavaCodegenTestGenerated.StaticFun.class, BlackBoxWithJavaCodegenTestGenerated.Visibility.class})
@InnerTestClasses({BlackBoxWithJavaCodegenTestGenerated.Annotations.class, BlackBoxWithJavaCodegenTestGenerated.CallableReference.class, BlackBoxWithJavaCodegenTestGenerated.Enum.class, BlackBoxWithJavaCodegenTestGenerated.Functions.class, BlackBoxWithJavaCodegenTestGenerated.InnerClass.class, BlackBoxWithJavaCodegenTestGenerated.Property.class, BlackBoxWithJavaCodegenTestGenerated.Sam.class, BlackBoxWithJavaCodegenTestGenerated.StaticFun.class, BlackBoxWithJavaCodegenTestGenerated.Visibility.class})
public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInBoxWithJava() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/boxWithJava"), Pattern.compile("^(.+)\\.kt$"), true);
@@ -134,6 +134,19 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
}
@TestMetadata("compiler/testData/codegen/boxWithJava/innerClass")
public static class InnerClass extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInInnerClass() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/boxWithJava/innerClass"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("kt3532.kt")
public void testKt3532() throws Exception {
doTestWithJava("compiler/testData/codegen/boxWithJava/innerClass/kt3532.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxWithJava/property")
public static class Property extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInProperty() throws Exception {
@@ -501,6 +514,7 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
suite.addTestSuite(CallableReference.class);
suite.addTestSuite(Enum.class);
suite.addTestSuite(Functions.class);
suite.addTestSuite(InnerClass.class);
suite.addTestSuite(Property.class);
suite.addTest(Sam.innerSuite());
suite.addTestSuite(StaticFun.class);
@@ -61,6 +61,11 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
doTest("compiler/testData/compileKotlinAgainstKotlin/InnerClass.A.kt");
}
@TestMetadata("InnerClassConstructor.A.kt")
public void testInnerClassConstructor() throws Exception {
doTest("compiler/testData/compileKotlinAgainstKotlin/InnerClassConstructor.A.kt");
}
@TestMetadata("InnerEnum.A.kt")
public void testInnerEnum() throws Exception {
doTest("compiler/testData/compileKotlinAgainstKotlin/InnerEnum.A.kt");