Fix concrete method inheritance in interfaces
For each non-abstract non-declared (i.e. inherited from supertypes) method in an interface we generate its static form to the TImpl, which calls the TImpl method from the corresponding supertype. The accidental override tests changed because we're now trying to generate the delegate for the super method, not knowing that it will clash with the declared method #KT-2888 Fixed #KT-5393 Fixed
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
interface A {
|
||||
fun foo(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
interface B : A
|
||||
|
||||
class C : B {
|
||||
override fun foo(): String {
|
||||
return super.foo()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return C().foo()
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
var result = "Fail"
|
||||
|
||||
interface A {
|
||||
var foo: String
|
||||
get() = result
|
||||
set(value) { result = value }
|
||||
}
|
||||
|
||||
interface B : A
|
||||
|
||||
class C : B {
|
||||
override var foo: String
|
||||
get() = super.foo
|
||||
set(value) { super.foo = value }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
C().foo = "OK"
|
||||
return C().foo
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
interface A {
|
||||
override fun toString(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
interface B : A
|
||||
|
||||
class C : B {
|
||||
override fun toString(): String {
|
||||
return super.toString()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = "${C()}"
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
interface A {
|
||||
fun foo(): Number {
|
||||
return 42
|
||||
}
|
||||
}
|
||||
|
||||
interface B : A
|
||||
|
||||
class C : B {
|
||||
override fun foo(): Int {
|
||||
return super.foo() as Int
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = C().foo()
|
||||
return if (x == 42) "OK" else "Fail: $x"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
interface A {
|
||||
fun foo() = "Fail"
|
||||
}
|
||||
|
||||
interface B : A
|
||||
|
||||
interface C : A {
|
||||
override fun foo() = "OK"
|
||||
}
|
||||
|
||||
interface D : B, C
|
||||
|
||||
class Impl : D
|
||||
|
||||
fun box(): String = Impl().foo()
|
||||
@@ -0,0 +1,18 @@
|
||||
interface A<T, U : Number, V : Any> {
|
||||
fun foo(t: T, u: U): V? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
interface B<T, V : Any> : A<T, Int, V>
|
||||
|
||||
class C : B<String, Runnable> {
|
||||
override fun foo(t: String, u: Int): Runnable? {
|
||||
return super.foo(t, u)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = C().foo("", 0)
|
||||
return if (x == null) "OK" else "Fail: $x"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
interface A {
|
||||
void foo();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
interface B : A {
|
||||
fun bar() = 1
|
||||
}
|
||||
|
||||
interface C : B
|
||||
|
||||
class D : C {
|
||||
override fun foo() {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val d = D()
|
||||
d.foo()
|
||||
d.bar()
|
||||
return "OK"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
interface A {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
interface B {
|
||||
fun foo(): String = "OK"
|
||||
}
|
||||
|
||||
interface C : A, B
|
||||
|
||||
// There's no 'foo' in A$$TImpl, proguard and other tools may fail if we generate calls to it
|
||||
// 0 INVOKESTATIC A\$\$TImpl.foo
|
||||
// 1 INVOKESTATIC B\$\$TImpl.foo
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// If we generate equals/hashCode/toString in all interfaces, there will be too much bytecode
|
||||
|
||||
interface A {
|
||||
fun foo(): Number = 42
|
||||
}
|
||||
|
||||
interface B : A
|
||||
|
||||
class C : B {
|
||||
override fun foo(): Int = super.foo() as Int
|
||||
}
|
||||
|
||||
// 0 equals
|
||||
// 0 hashCode
|
||||
// 0 toString
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
public interface Base {
|
||||
default String foo() {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
interface K1 : Base
|
||||
|
||||
interface K2 : K1
|
||||
|
||||
interface K3 : K2
|
||||
|
||||
class C : K3 {
|
||||
override fun foo() = super.foo()
|
||||
}
|
||||
|
||||
fun box(): String = C().foo()
|
||||
Reference in New Issue
Block a user