KT-3389: Local class construction results in CompilationException && KT-2873 && KT-3210
KT-2873: VerifyError on instantiating a local class inside a closure KT-3210 Inline Class: CompilationException: Back-end (JVM) Internal error: wrong code generated java.lang.ArrayIndexOutOfBoundsException null #KT-3389 Fixed
This commit is contained in:
@@ -3160,7 +3160,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> 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());
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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"))
|
||||
}
|
||||
@@ -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"))
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun foo() : String {
|
||||
val u = {
|
||||
class B(val data : String)
|
||||
B("OK").data
|
||||
}
|
||||
return u()
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
foo()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return foo()
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.example
|
||||
|
||||
trait SomeTrait {}
|
||||
|
||||
trait KotlinProcessor<T> {
|
||||
fun execute(callback: KotlinCallback<T>?);
|
||||
}
|
||||
|
||||
trait KotlinCallback<T> {
|
||||
fun on(t : T);
|
||||
}
|
||||
|
||||
public class Test(name : String) : KotlinProcessor<SomeTrait> {
|
||||
public override fun execute(callback: KotlinCallback<SomeTrait>?) {
|
||||
if(callback != null) {
|
||||
class InlineTrait : SomeTrait {}
|
||||
|
||||
var inlineTrait = InlineTrait()
|
||||
callback.on(inlineTrait)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
var f = "fail"
|
||||
Test("OK").execute(object : KotlinCallback<SomeTrait> {
|
||||
override fun on(t: SomeTrait) {
|
||||
f = "OK"
|
||||
}
|
||||
})
|
||||
return f
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class A {
|
||||
fun a () : String {
|
||||
class B() {
|
||||
fun s() : String = "OK"
|
||||
}
|
||||
return B().s()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return A().a()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
trait Runnable {
|
||||
fun run()
|
||||
}
|
||||
|
||||
class C {
|
||||
fun f() {
|
||||
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyRunnable<!>(): Runnable {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user