diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 68a61a335a7..1e5a8a383b8 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -3160,7 +3160,10 @@ public class ExpressionCodegen extends JetVisitor implem v.pop(); } - pushClosureOnStack(closure, true); + //Resolved call to local class constructor doesn't have resolvedCall.getThisObject() and resolvedCall.getReceiverArgument() + //so we need generate closure on stack + //See StackValue.receiver for more info + pushClosureOnStack(closure, resolvedCall.getThisObject().exists() || resolvedCall.getReceiverArgument().exists()); CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor); invokeMethodWithArguments(method, resolvedCall, null, StackValue.none()); diff --git a/compiler/testData/codegen/box/localClasses/inExtensionFunction.kt b/compiler/testData/codegen/box/localClasses/inExtensionFunction.kt new file mode 100644 index 00000000000..0a4fbfbbbf0 --- /dev/null +++ b/compiler/testData/codegen/box/localClasses/inExtensionFunction.kt @@ -0,0 +1,17 @@ +package test + +fun A.a(): String { + class B { + val b : String + get() = this@a.s + } + return B().b +} + +class A { + val s : String = "OK" +} + +fun box() : String { + return A().a() +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/localClasses/inExtensionProperty.kt b/compiler/testData/codegen/box/localClasses/inExtensionProperty.kt new file mode 100644 index 00000000000..6b0ed7cb97d --- /dev/null +++ b/compiler/testData/codegen/box/localClasses/inExtensionProperty.kt @@ -0,0 +1,18 @@ +package test + +val A.a: String + get() { + class B { + val b : String + get() = this@a.s + } + return B().b + } + +class A { + val s : String = "OK" +} + +fun box() : String { + return A().a +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/localClasses/inLocalExtensionFunction.kt b/compiler/testData/codegen/box/localClasses/inLocalExtensionFunction.kt new file mode 100644 index 00000000000..d7231d40d3d --- /dev/null +++ b/compiler/testData/codegen/box/localClasses/inLocalExtensionFunction.kt @@ -0,0 +1,24 @@ +package test + +class C(val s : String) { + fun A.a(): String { + class B { + val b : String + get() = this@a.s + this@C.s + } + return B().b + } + + fun test(a : A) : String { + return a.a() + } +} + +class A(val s: String) { + + +} + +fun box() : String { + return C("K").test(A("O")) +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/localClasses/inLocalExtensionProperty.kt b/compiler/testData/codegen/box/localClasses/inLocalExtensionProperty.kt new file mode 100644 index 00000000000..6a628f41320 --- /dev/null +++ b/compiler/testData/codegen/box/localClasses/inLocalExtensionProperty.kt @@ -0,0 +1,23 @@ +package test + +class C(val s : String) { + val A.a: String + get() { + class B { + val b : String + get() = this@a.s + this@C.s + } + return B().b + } + + fun test(a : A) : String { + return a.a + } +} + +class A(val s: String) { +} + +fun box() : String { + return C("K").test(A("O")) +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/localClasses/innerClassInLocalClass.kt b/compiler/testData/codegen/box/localClasses/innerClassInLocalClass.kt new file mode 100644 index 00000000000..72d84e5ddac --- /dev/null +++ b/compiler/testData/codegen/box/localClasses/innerClassInLocalClass.kt @@ -0,0 +1,17 @@ +class A { + val a = 1 + fun calc () : Int { + class B() { + val b = 2 + inner class C { + val c = 3 + fun calc() = this@A.a + this@B.b + this.c + } + } + return B().C().calc() + } +} + +fun box() : String { + return if (A().calc() == 6) "OK" else "fail" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/localClasses/kt2873.kt b/compiler/testData/codegen/box/localClasses/kt2873.kt new file mode 100644 index 00000000000..6bb8dafadfd --- /dev/null +++ b/compiler/testData/codegen/box/localClasses/kt2873.kt @@ -0,0 +1,15 @@ +fun foo() : String { + val u = { + class B(val data : String) + B("OK").data + } + return u() +} + +fun main(args: Array) { + foo() +} + +fun box(): String { + return foo() +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/localClasses/kt3210.kt b/compiler/testData/codegen/box/localClasses/kt3210.kt new file mode 100644 index 00000000000..da90a52d584 --- /dev/null +++ b/compiler/testData/codegen/box/localClasses/kt3210.kt @@ -0,0 +1,32 @@ +package org.example + +trait SomeTrait {} + +trait KotlinProcessor { + fun execute(callback: KotlinCallback?); +} + +trait KotlinCallback { + fun on(t : T); +} + +public class Test(name : String) : KotlinProcessor { + public override fun execute(callback: KotlinCallback?) { + if(callback != null) { + class InlineTrait : SomeTrait {} + + var inlineTrait = InlineTrait() + callback.on(inlineTrait) + } + } +} + +fun box() : String { + var f = "fail" + Test("OK").execute(object : KotlinCallback { + override fun on(t: SomeTrait) { + f = "OK" + } + }) + return f +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/localClasses/kt3389.kt b/compiler/testData/codegen/box/localClasses/kt3389.kt new file mode 100644 index 00000000000..dea8cfab8eb --- /dev/null +++ b/compiler/testData/codegen/box/localClasses/kt3389.kt @@ -0,0 +1,14 @@ +package t + +class Reproduce { + + fun test(): String { + [data] class Foo(val bar: String, val baz: Int) + val foo = Foo("OK", 5) + return foo.bar + } +} + +fun box() : String { + return Reproduce().test() +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/localClasses/localClass.kt b/compiler/testData/codegen/box/localClasses/localClass.kt new file mode 100644 index 00000000000..d8cdb7552fd --- /dev/null +++ b/compiler/testData/codegen/box/localClasses/localClass.kt @@ -0,0 +1,12 @@ +class A { + fun a () : String { + class B() { + fun s() : String = "OK" + } + return B().s() + } +} + +fun box() : String { + return A().a() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/kt2052.kt b/compiler/testData/diagnostics/tests/override/kt2052.kt new file mode 100644 index 00000000000..74edd79997e --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt2052.kt @@ -0,0 +1,10 @@ +trait Runnable { + fun run() +} + +class C { + fun f() { + class MyRunnable(): Runnable { + } + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 31414def652..4c11d28be66 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -3590,6 +3590,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/override/kt1862.kt"); } + @TestMetadata("kt2052.kt") + public void testKt2052() throws Exception { + doTest("compiler/testData/diagnostics/tests/override/kt2052.kt"); + } + @TestMetadata("kt880.kt") public void testKt880() throws Exception { doTest("compiler/testData/diagnostics/tests/override/kt880.kt"); diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java index 1fcde357b04..16187b82f7d 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -2281,6 +2281,51 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/localClasses/enum.kt"); } + @TestMetadata("inExtensionFunction.kt") + public void testInExtensionFunction() throws Exception { + doTest("compiler/testData/codegen/box/localClasses/inExtensionFunction.kt"); + } + + @TestMetadata("inExtensionProperty.kt") + public void testInExtensionProperty() throws Exception { + doTest("compiler/testData/codegen/box/localClasses/inExtensionProperty.kt"); + } + + @TestMetadata("inLocalExtensionFunction.kt") + public void testInLocalExtensionFunction() throws Exception { + doTest("compiler/testData/codegen/box/localClasses/inLocalExtensionFunction.kt"); + } + + @TestMetadata("inLocalExtensionProperty.kt") + public void testInLocalExtensionProperty() throws Exception { + doTest("compiler/testData/codegen/box/localClasses/inLocalExtensionProperty.kt"); + } + + @TestMetadata("innerClassInLocalClass.kt") + public void testInnerClassInLocalClass() throws Exception { + doTest("compiler/testData/codegen/box/localClasses/innerClassInLocalClass.kt"); + } + + @TestMetadata("kt2873.kt") + public void testKt2873() throws Exception { + doTest("compiler/testData/codegen/box/localClasses/kt2873.kt"); + } + + @TestMetadata("kt3210.kt") + public void testKt3210() throws Exception { + doTest("compiler/testData/codegen/box/localClasses/kt3210.kt"); + } + + @TestMetadata("kt3389.kt") + public void testKt3389() throws Exception { + doTest("compiler/testData/codegen/box/localClasses/kt3389.kt"); + } + + @TestMetadata("localClass.kt") + public void testLocalClass() throws Exception { + doTest("compiler/testData/codegen/box/localClasses/localClass.kt"); + } + @TestMetadata("noclosure.kt") public void testNoclosure() throws Exception { doTest("compiler/testData/codegen/box/localClasses/noclosure.kt");