JvmDefault. Allow non default inheritance with special flag
#KT-47000
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// FULL_JDK
|
||||
// JVM_TARGET: 1.8
|
||||
// WITH_RUNTIME
|
||||
// MODULE: lib
|
||||
// !JVM_DEFAULT_MODE: all
|
||||
// FILE: Foo.kt
|
||||
|
||||
interface Foo {
|
||||
fun toOverride(): String = "fail"
|
||||
|
||||
fun nonOverride(): String = "K"
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// !JVM_DEFAULT_MODE: disable
|
||||
// !JVM_DEFAULT_ALLOW_NON_DEFAULT_INHERITANCE
|
||||
// FILE: main.kt
|
||||
|
||||
interface Derived : Foo {
|
||||
override fun toOverride(): String {
|
||||
return "O"
|
||||
}
|
||||
}
|
||||
|
||||
class DerivedClass : Derived
|
||||
|
||||
|
||||
fun box(): String {
|
||||
checkMethodExists(DerivedClass::class.java, "toOverride")
|
||||
checkNoMethod(DerivedClass::class.java, "nonOverride")
|
||||
|
||||
val value = DerivedClass()
|
||||
return value.toOverride() + value.nonOverride()
|
||||
}
|
||||
|
||||
fun checkNoMethod(clazz: Class<*>, name: String, vararg parameterTypes: Class<*>) {
|
||||
try {
|
||||
clazz.getDeclaredMethod(name, *parameterTypes)
|
||||
}
|
||||
catch (e: NoSuchMethodException) {
|
||||
return
|
||||
}
|
||||
throw AssertionError("fail: method $name was found in " + clazz)
|
||||
}
|
||||
|
||||
fun checkMethodExists(clazz: Class<*>, name: String, vararg parameterTypes: Class<*>) {
|
||||
try {
|
||||
clazz.getDeclaredMethod(name, *parameterTypes)
|
||||
return
|
||||
}
|
||||
catch (e: NoSuchMethodException) {
|
||||
throw AssertionError("fail: method $name was not found in " + clazz, e)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// FULL_JDK
|
||||
// JVM_TARGET: 1.8
|
||||
// WITH_RUNTIME
|
||||
// MODULE: lib
|
||||
// !JVM_DEFAULT_MODE: all
|
||||
// FILE: Foo.kt
|
||||
|
||||
interface Foo {
|
||||
fun toOverride(): List<String> = null!!
|
||||
|
||||
fun nonOverride(): List<String> = Thread.currentThread().getStackTrace().map { it.className + "." + it.methodName }
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// !JVM_DEFAULT_MODE: disable
|
||||
// !JVM_DEFAULT_ALLOW_NON_DEFAULT_INHERITANCE
|
||||
// FILE: main.kt
|
||||
|
||||
interface Derived : Foo {
|
||||
override fun toOverride() = Thread.currentThread().getStackTrace().map { it.className + "." + it.methodName }
|
||||
}
|
||||
|
||||
class DerivedClass : Derived
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val override = DerivedClass().toOverride()
|
||||
if (override[1] != "Derived\$DefaultImpls.toOverride") return "fail 1: ${override[1]}"
|
||||
if (override[2] != "DerivedClass.toOverride") return "fail 2: ${override[2]}"
|
||||
if (override[3] != "MainKt.box") return "fail 3: ${override[3]}"
|
||||
|
||||
val nonOverride = DerivedClass().nonOverride()
|
||||
if (nonOverride[1] != "Foo.nonOverride") return "fail 3: ${nonOverride[1]}"
|
||||
if (nonOverride[2] != "MainKt.box") return "fail 4: ${nonOverride[2]}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// CHECK_BYTECODE_LISTING
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// JVM_TARGET: 1.8
|
||||
// WITH_RUNTIME
|
||||
// MODULE: lib
|
||||
// !JVM_DEFAULT_MODE: all
|
||||
// FILE: Foo.kt
|
||||
|
||||
interface Foo<T> {
|
||||
fun foo(p: T) = p
|
||||
}
|
||||
|
||||
interface Foo2<T> {
|
||||
fun foo(p: T): T = null!!
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// !JVM_DEFAULT_MODE: disable
|
||||
// !JVM_DEFAULT_ALLOW_NON_DEFAULT_INHERITANCE
|
||||
// FILE: main.kt
|
||||
class DerivedClass : Foo<String>
|
||||
|
||||
interface DerivedInterface<T> : Foo2<T> {
|
||||
override fun foo(p: T) = p
|
||||
}
|
||||
|
||||
class DerivedClassWithSpecialization : DerivedInterface<String>
|
||||
|
||||
fun box(): String {
|
||||
return DerivedClass().foo("O") + DerivedClassWithSpecialization().foo("K")
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
Module: lib
|
||||
@kotlin.Metadata
|
||||
public interface Foo {
|
||||
// source: 'Foo.kt'
|
||||
public method foo(p0: java.lang.Object): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public interface Foo2 {
|
||||
// source: 'Foo.kt'
|
||||
public method foo(p0: java.lang.Object): java.lang.Object
|
||||
}
|
||||
Module: main
|
||||
@kotlin.Metadata
|
||||
public final class DerivedClass {
|
||||
// source: 'main.kt'
|
||||
public method <init>(): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class DerivedClassWithSpecialization {
|
||||
// source: 'main.kt'
|
||||
public method <init>(): void
|
||||
public @org.jetbrains.annotations.NotNull method foo(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String
|
||||
public synthetic bridge method foo(p0: java.lang.Object): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class DerivedInterface$DefaultImpls {
|
||||
// source: 'main.kt'
|
||||
public static method foo(@org.jetbrains.annotations.NotNull p0: DerivedInterface, p1: java.lang.Object): java.lang.Object
|
||||
public final inner class DerivedInterface$DefaultImpls
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public interface DerivedInterface {
|
||||
// source: 'main.kt'
|
||||
public abstract method foo(p0: java.lang.Object): java.lang.Object
|
||||
public final inner class DerivedInterface$DefaultImpls
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class MainKt {
|
||||
// source: 'main.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// CHECK_BYTECODE_LISTING
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// JVM_TARGET: 1.8
|
||||
// WITH_RUNTIME
|
||||
// MODULE: lib
|
||||
// !JVM_DEFAULT_MODE: all
|
||||
// FILE: Foo.kt
|
||||
|
||||
interface Foo<T> {
|
||||
fun foo(p: T) = p
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// !JVM_DEFAULT_MODE: disable
|
||||
// !JVM_DEFAULT_ALLOW_NON_DEFAULT_INHERITANCE
|
||||
// FILE: main.kt
|
||||
interface DerivedInterface<T> : Foo<T>
|
||||
|
||||
class DerivedClass : DerivedInterface<String> {
|
||||
override fun foo(p: String) = super.foo(p)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return DerivedClass().foo("OK")
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
Module: lib
|
||||
@kotlin.Metadata
|
||||
public interface Foo {
|
||||
// source: 'Foo.kt'
|
||||
public method foo(p0: java.lang.Object): java.lang.Object
|
||||
}
|
||||
Module: main
|
||||
@kotlin.Metadata
|
||||
public final class DerivedClass {
|
||||
// source: 'main.kt'
|
||||
public method <init>(): void
|
||||
public @org.jetbrains.annotations.NotNull method foo(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String
|
||||
public synthetic bridge method foo(p0: java.lang.Object): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public interface DerivedInterface {
|
||||
// source: 'main.kt'
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class MainKt {
|
||||
// source: 'main.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
}
|
||||
Reference in New Issue
Block a user