-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
8
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM
Kotlin Programming Language is open-source and free to use. It is developed by JetBrains and released under the Apache 2.0 license.
Normally, code written in Kotlin Programming Language is compiled with Kotlin compiler (kotlinc) and run with the JVM. When code is compiled, it generates .class files known as bytecode which contains Kotlin and Java code, and that can be compiled with javac. Kotlin interacts seamlessly with Java libraries and the JVM runtime, ensuring smooth integration with existing Java projects.
A special type in Kotlin is represented with the word "Nothing" that represents a value that never exists or a function that never returns. Due to lack of Nothing in Java, the type parameter in A0's interface I0<T2, Nothing> is translated into I0 and Nothing with return type translated into Void. But such Java code cannot be compiled because there is no good Java representation for Nothing.
The bytecode difference between code with and without Nothing is that A0 either implements I0 or I0<T2, ...>. In both cases, the Kotlin compiler generates correct overrides for I0::func (either directly or as a synthetic bridge). And javac must be able to correctly map overrides for inheritance from a raw supertype (I0).
I believe it is a javac bug since the problem does not exists in JDK 11 and above but only in JDK 8.
STEPS TO REPRODUCE THE PROBLEM
1. Compile A0.kt, I0.kt, and Main.kt with Kotlin
kotlinc I0.kt A0.kt Main.kt
2. Put them in the same folder and compile A1.java with JDK 8
javac A1.java -cp .
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program compiles with success.
ACTUAL -
The program fails with:
A1.java:1: error: name clash: func(T2) in A0 and func(T0) in I0 have the same erasure, yet neither overrides the other
public class A1 extends A0<String> {}
^
where T2,T0 are type-variables:
T2 extends Object declared in class A0
T0 extends Object declared in interface I0
1 error
---------- BEGIN SOURCE ----------
public class A1 extends A0<String> {}
---------- END SOURCE ----------
FREQUENCY: Always
Kotlin Programming Language is open-source and free to use. It is developed by JetBrains and released under the Apache 2.0 license.
Normally, code written in Kotlin Programming Language is compiled with Kotlin compiler (kotlinc) and run with the JVM. When code is compiled, it generates .class files known as bytecode which contains Kotlin and Java code, and that can be compiled with javac. Kotlin interacts seamlessly with Java libraries and the JVM runtime, ensuring smooth integration with existing Java projects.
A special type in Kotlin is represented with the word "Nothing" that represents a value that never exists or a function that never returns. Due to lack of Nothing in Java, the type parameter in A0's interface I0<T2, Nothing> is translated into I0 and Nothing with return type translated into Void. But such Java code cannot be compiled because there is no good Java representation for Nothing.
The bytecode difference between code with and without Nothing is that A0 either implements I0 or I0<T2, ...>. In both cases, the Kotlin compiler generates correct overrides for I0::func (either directly or as a synthetic bridge). And javac must be able to correctly map overrides for inheritance from a raw supertype (I0).
I believe it is a javac bug since the problem does not exists in JDK 11 and above but only in JDK 8.
STEPS TO REPRODUCE THE PROBLEM
1. Compile A0.kt, I0.kt, and Main.kt with Kotlin
kotlinc I0.kt A0.kt Main.kt
2. Put them in the same folder and compile A1.java with JDK 8
javac A1.java -cp .
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program compiles with success.
ACTUAL -
The program fails with:
A1.java:1: error: name clash: func(T2) in A0 and func(T0) in I0 have the same erasure, yet neither overrides the other
public class A1 extends A0<String> {}
^
where T2,T0 are type-variables:
T2 extends Object declared in class A0
T0 extends Object declared in interface I0
1 error
---------- BEGIN SOURCE ----------
public class A1 extends A0<String> {}
---------- END SOURCE ----------
FREQUENCY: Always