Error on runtime with extension functions (Maybe for the lack of reified generics)


#1

As part of the next version of funKTionale I'm implementing a flip extension function.

public fun<P1, P2, R> Function1<P1, Function1<P2, R>>.flip(): (P2) -> (P1) -> R {
    return {(p2: P2) -> {(p1: P1)  -> this(p1)(p2) } }
}

So far, so good, the IDE, compiler and tests works fine

Then I define my next flip extension function

public fun<P1, P2, P3, R> Function1<P1, Function1<P2, Function1<P3, R>>>.flip(): (P3) -> (P2) -> (P1) -> R {
    return {(p3: P3) -> {(p2: P2) -> {(p1: P1)  -> this(p1)(p2)(p3) } } }
}

The IDE is happy, also the compiler, but when I execute my tests

java.lang.ClassFormatError: Duplicate method name&signature in class file org/funktionale/flip/FlipPackage   at java.lang.ClassLoader.defineClass1(Native Method)   at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)   at java.lang.ClassLoader.defineClass(ClassLoader.java:615)   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)   at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)   at java.net.URLClassLoader.access$000(URLClassLoader.java:58)   at java.net.URLClassLoader$1.run(URLClassLoader.java:197)   at java.security.AccessController.doPrivileged(Native Method)   at java.net.URLClassLoader.findClass(URLClassLoader.java:190)   at java.lang.ClassLoader.loadClass(ClassLoader.java:306)   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)   at java.lang.ClassLoader.loadClass(ClassLoader.java:247)   at org.funktionale.flip.FlipTest.testFliping(FlipTest.kt:17)

Lack of reified generics? Bug on Kotlin runtime?


#2

Bug in diagnostics: you are creating two functions with the same name and one parameter (receiver) of type Function1<...>. Their (erased) Java signatures are identical, which is forbidden.

Please report the bug to the tracker. Thanks