Fix function invocation mangling rule

Mangle invocations of functions with value classes in signature which
override (directly or indirectly) a method declared in Kotlin code.
Otherwise, NoSuchMethodError is being thrown.

^KT-55945: Fixed
This commit is contained in:
vladislav.grechko
2023-02-07 20:59:30 +01:00
committed by Space Team
parent f80ed4592d
commit 457837a255
29 changed files with 744 additions and 4 deletions
@@ -0,0 +1,22 @@
// WITH_STDLIB
// TARGET_BACKEND: JVM_IR
// LANGUAGE: +MangleCallsToJavaMethodsWithValueClasses
// FILE: KotlinParent.kt
open class KotlinParent {
fun foo(type: InlineType) = 42
@JvmInline
value class InlineType(val id: Int)
}
// FILE: JavaChild.java
class JavaChild extends KotlinParent {}
// FILE: box.kt
fun box(): String {
if (JavaChild().foo(KotlinParent.InlineType(1)) != 42) return "Fail"
return "OK"
}
@@ -0,0 +1,31 @@
// WITH_STDLIB
// TARGET_BACKEND: JVM_IR
// FILE: JavaBase.java
import kotlin.UInt;
public class JavaBase {
public int foo(UInt x)
{
return 42;
}
}
// FILE: JavaChild.java
public class JavaChild extends JavaBase {}
// FILE: KotlinChild.kt
class KotlinChild : JavaChild()
// FILE: box.kt
fun box(): String {
if (JavaBase().foo(0.toUInt()) != 42) return "Fail 1"
if (JavaChild().foo(0.toUInt()) != 42) return "Fail 2"
if (KotlinChild().foo(0.toUInt()) != 42) return "Fail 3"
return "OK"
}
@@ -0,0 +1,34 @@
// WITH_STDLIB
// TARGET_BACKEND: JVM_IR
// FILE: JavaBase.java
import kotlin.UInt;
public class JavaBase {
public int foo(UInt x)
{
return 42;
}
}
// FILE: JavaChild.java
public class JavaChild extends JavaBase {}
// FILE: KotlinChild.kt
class KotlinChild : JavaChild() {
override fun foo(x : UInt) = 24
}
// FILE: box.kt
fun box(): String {
if (JavaBase().foo(0.toUInt()) != 42) return "Fail 1"
if (JavaChild().foo(0.toUInt()) != 42) return "Fail 2"
if (KotlinChild().foo(0.toUInt()) != 24) return "Fail 3"
return "OK"
}
@@ -0,0 +1,34 @@
// WITH_STDLIB
// TARGET_BACKEND: JVM_IR
// FILE: KotlinInterface.kt
public interface KotlinInterface {
fun foo(x: UInt): Int
}
// FILE: JavaInterface.java
import kotlin.UInt;
public interface JavaInterface {
int foo(UInt x);
}
// FILE: JavaInterfaceChildOfKotlin.java
public interface JavaInterfaceChildOfKotlin extends KotlinInterface {}
// FILE: KotlinChild.kt
class KotlinChild : JavaInterface, JavaInterfaceChildOfKotlin {
override fun foo(x: UInt) = 42
}
// FILE: box.kt
fun box(): String {
if (KotlinChild().foo(0.toUInt()) != 42) return "Fail"
return "OK"
}
@@ -0,0 +1,28 @@
// WITH_STDLIB
// TARGET_BACKEND: JVM_IR
// FILE: KotlinBase.kt
open class KotlinBase {
open fun foo(x : UInt) = 42
}
// FILE: JavaChild.java
public class JavaChild extends KotlinBase {}
// FILE: KotlinChild.kt
class KotlinChild : JavaChild() {
override fun foo(x : UInt) = 24
}
// FILE: box.kt
fun box(): String {
if (KotlinBase().foo(0.toUInt()) != 42) return "Fail 1"
if (JavaChild().foo(0.toUInt()) != 42) return "Fail 2"
if (KotlinChild().foo(0.toUInt()) != 24) return "Fail 3"
return "OK"
}
@@ -0,0 +1,24 @@
// WITH_STDLIB
// TARGET_BACKEND: JVM_IR
// LANGUAGE: -MangleCallsToJavaMethodsWithValueClasses
// FILE: KotlinParent.kt
open class KotlinParent {
fun foo(x: UInt) = x.toInt()
}
// FILE: JavaChild.java
public class JavaChild extends KotlinParent {
public int foo(int x) {
return 42;
}
}
// FILE: box.kt
fun box(): String {
if (JavaChild().foo(0.toUInt()) != 42) return "Fail"
return "OK"
}