Wondering if this is a known issue (I did't see an...
# k2-early-adopters
t
Wondering if this is a known issue (I did't see anything obvious on YouTrack). If not, I'll create an issue. Issue: K2 compiled code fails when a value class method is called, where the value class uses delegation and the delegate is a Java interface with a default method, and the value class method being called is the java interface default method. I am getting:
java.lang.NoSuchMethodError: MyInterfaceWrapperOfJavaInterface.withJavaDefaultInterfaceMethod-impl(LMyJavaInterface;Ljava/lang/String;)Ljava/lang/String
If the interface is created as a kotlin interface, there isn't a problem. However, I ran into this working with an existing Java library (playwright), which has an existing interface I am trying to use. Here's a small repo showing the issue (see IssueMain.kt#main()): https://github.com/twadzins/k2-issue-delegate-value-class Looking at the decompiled code diff in the screenshot (left is non k2, right is k2), it seems that the non k2 is using box-impl(), but the k2 version does not. In both cases, the decompiled value class does indeed not contain the
withJavaDefaultInterfaceMethod
method. I see that I can workaround it if, in the value class body, I override the "missing" default method and have it just call
super.withJavaDefaultInterfaceMethod()
IssueMain.kt:
Copy code
/**
 * From <https://kotlinlang.org/docs/inline-classes.html#inline-classes-and-delegation>
 */
@JvmInline
value class MyInterfaceWrapperOfJavaInterface(val m: MyJavaInterface) : MyJavaInterface by m


fun main() {
    val myJava = MyInterfaceWrapperOfJavaInterface(MyJavaInterfaceImpl())
    println(myJava.withJavaDefaultInterfaceMethod("Worked with one arg (with default interface)")) // works on non K2, fails with K2
}
Java interface: MyJavaInterface.java:
Copy code
public interface MyJavaInterface {
    String withJavaDefaultInterfaceMethod(String value, String otherString);

    default String withJavaDefaultInterfaceMethod(String value) {
        return withJavaDefaultInterfaceMethod(value, null);
    }
...
Here's a log of it working without k2 and failing with k2:
Copy code
% ./gradlew run -Pkotlin.experimental.tryK2=false

> Task :run
Worked with one arg (with default interface)

BUILD SUCCESSFUL in 1s
3 actionable tasks: 2 executed, 1 up-to-date

 
% ./gradlew run -Pkotlin.experimental.tryK2=true 

> Configure project :
ATTENTION: 'kotlin.experimental.tryK2' is an experimental option enabled in the project for trying out the new Kotlin K2 compiler only.
Please refrain from using it in production code and provide feedback to the Kotlin team for any issues encountered via <https://kotl.in/issue>

> Task :compileKotlin
w: Language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features

> Task :run FAILED
Exception in thread "main" java.lang.NoSuchMethodError: MyInterfaceWrapperOfJavaInterface.withJavaDefaultInterfaceMethod-impl(LMyJavaInterface;Ljava/lang/String;)Ljava/lang/String;
        at IssueMainKt.main(IssueMain.kt:13)
        at IssueMainKt.main(IssueMain.kt)
##### 'kotlin.experimental.tryK2' results (Kotlin/Native not checked) #####
:compileKotlin: 2.0 language version
##### 100% (1/1) tasks have been compiled with Kotlin 2.0 #####

FAILURE: Build failed with an exception.
d
Thank you for the great investigation! Did you create a ticket with all this information?
t
Not yet, will make one now and post a link here
👍 1