Don't generate implicit overrides delegating to Java defaults

#KT-40920 Fixed
This commit is contained in:
Mikhael Bogdanov
2020-08-10 12:24:54 +02:00
parent 07aee8831e
commit 607f99ed3c
11 changed files with 339 additions and 2 deletions
@@ -0,0 +1,28 @@
// !JVM_DEFAULT_MODE: disable
// JVM_TARGET: 1.8
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: JBase.java
public interface JBase extends Base {
default String test() {
return "OK";
}
}
// FILE: main.kt
// WITH_RUNTIME
interface Base {
fun test(): String = "Base"
}
interface LeftBase : Base
interface Right : JBase
interface Child : LeftBase, Right
fun box(): String {
return object : Child {}.test()
}
@@ -0,0 +1,26 @@
// !JVM_DEFAULT_MODE: disable
// JVM_TARGET: 1.8
// TARGET_BACKEND: JVM
// FILE: Base.java
public interface Base {
default String test() {
return "Base";
}
}
// FILE: main.kt
// WITH_RUNTIME
interface LeftBase : Base
interface Right : Base {
override fun test(): String = "OK"
}
interface Child : LeftBase, Right
fun box(): String {
return object : Child {}.test()
}
@@ -0,0 +1,28 @@
// !JVM_DEFAULT_MODE: disable
// JVM_TARGET: 1.8
// TARGET_BACKEND: JVM
// FILE: Base.java
public interface Base {
default String test() {
return "Base";
}
}
// FILE: Left.java
public interface Left extends Base {
}
// FILE: main.kt
// WITH_RUNTIME
interface Right : Base {
override fun test(): String = "OK"
}
interface Child : Left, Right
fun box(): String {
return object : Child {}.test()
}
@@ -0,0 +1,76 @@
// !JVM_DEFAULT_MODE: disable
// JVM_TARGET: 1.8
// TARGET_BACKEND: JVM
// FILE: main.kt
// WITH_RUNTIME
// FULL_JDK
// IGNORE_BACKEND_FIR: JVM_IR
var result = ""
interface A<K, V> : MutableMap<K, V>
interface Left<K, V> : A<K, V>
interface Right<K, V> : A<K, V> {
override fun remove(key: K): V? {
result += key.toString() + ";"
return null
}
override public fun getOrDefault(key: K, defaultValue: V): V {
result += key.toString() + ";"
return defaultValue
}
}
internal class MyMap : Left<String, String>, Right<String, String> {
override val size: Int
get() = null!!
override fun isEmpty(): Boolean {
return true
}
override fun containsKey(key: String): Boolean {
return false
}
override fun containsValue(value: String): Boolean {
return false
}
override fun get(key: String): String? {
TODO("Not yet implemented")
}
override fun put(key: String, value: String): String? {
result += "$key=$value;"
return null
}
override fun putAll(from: Map<out String, String>) {
}
override fun clear() {}
override val keys: MutableSet<String>
get() = null!!
override val values: MutableCollection<String>
get() = null!!
override val entries: MutableSet<MutableMap.MutableEntry<String, String>>
get() = null!!
}
fun box(): String {
val map = MyMap()
map["O"] = "fail"
map.remove("O")
val value = map.getOrDefault("O", "OK")
if (result != "O=fail;O;O;") return "fail 3: $result"
return value
}