Generate bridges for trait implementations properly

The intent was to keep the bridge codegen model as simple as possible: we
should be able to figure out all necessary bridges only by a minimal interface
that FunctionHandle provides (isAbstract, isDeclaration, getOverridden)

Add different tests for bridges

 #KT-318 Obsolete
This commit is contained in:
Alexander Udalov
2014-04-07 22:29:00 +04:00
parent 4a12ea9bda
commit 79e7ee91e4
14 changed files with 289 additions and 79 deletions
@@ -0,0 +1,28 @@
import java.util.ArrayList
import java.util.Arrays
abstract class A {
abstract fun foo(): List<String>
}
trait B {
fun foo(): ArrayList<String> = ArrayList(Arrays.asList("B"))
}
open class C : A(), B
trait D {
fun foo(): Collection<String>
}
class E : D, C()
fun box(): String {
val e = E()
var r = e.foo()[0]
r += (e : D).foo().iterator().next()
r += (e : C).foo()[0]
r += (e : B).foo()[0]
r += (e : A).foo()[0]
return if (r == "BBBBB") "OK" else "Fail: $r"
}
@@ -0,0 +1,17 @@
abstract class A {
abstract fun foo(): Any
}
trait B {
fun foo(): String = "B"
}
trait C : A, B
class D : A(), C
fun box(): String {
val d = D()
val r = d.foo() + (d : C).foo() + (d : B).foo() + (d : A).foo()
return if (r == "BBBB") "OK" else "Fail: $r"
}
@@ -0,0 +1,23 @@
var result = ""
trait A {
var foo: String
get() = result
set(value) {
result += value
}
}
abstract class B {
abstract var foo: Any
}
class C : A, B()
fun box(): String {
val c = C()
c.foo = "1"
(c : B).foo = "2"
(c : A).foo = "3"
return if (result == "123") "OK" else "Fail: $result"
}
@@ -0,0 +1,18 @@
trait A {
fun foo(): String = "A"
}
trait B {
fun foo(): Any
}
class C : A, B
fun box(): String {
val c = C()
var result = ""
result += c.foo()
result += (c : B).foo()
result += (c : A).foo()
return if (result == "AAA") "OK" else "Fail: $result"
}
@@ -0,0 +1,23 @@
var result = ""
trait Base
open class Child : Base
trait A<T : Base> {
fun <E : T> foo(a : E) {
result += "A"
}
}
class B : A<Child> {
override fun <E : Child> foo(a : E) {
result += "B"
}
}
fun box(): String {
val b = B()
b.foo(Child())
(b : A<Child>).foo(Child())
return if (result == "BB") "OK" else "Fail: $result"
}
@@ -0,0 +1,22 @@
import java.util.ArrayList
import java.util.Arrays
trait A {
fun foo(): Collection<String>
}
trait B : A {
override fun foo(): MutableCollection<String>
}
class C : B {
override fun foo(): MutableList<String> = ArrayList(Arrays.asList("C"))
}
fun box(): String {
val c = C()
var r = c.foo().iterator().next()
r += (c : B).foo().iterator().next()
r += (c : A).foo().iterator().next()
return if (r == "CCC") "OK" else "Fail: $r"
}
@@ -0,0 +1,15 @@
trait A {
fun foo(): Any = "A"
}
trait B : A {
override fun foo(): String = "B"
}
class C : B
fun box(): String {
val c = C()
var r = c.foo() + (c : B).foo() + (c : A).foo()
return if (r == "BBB") "OK" else "Fail: $r"
}
@@ -0,0 +1,15 @@
open class A {
open fun foo(): Any = "A"
}
trait B : A {
override fun foo(): String = "B"
}
class C : A(), B
fun box(): String {
val c = C()
val r = c.foo() + (c : B).foo() + (c : A).foo()
return if (r == "BBB") "OK" else "Fail: $r"
}