Files
kotlin-fork/compiler/testData/codegen/box/classes/kt2224.kt
T
Alexander Udalov 41a416da60 Move blackBoxFile() testData to box/ directory
Delete all test methods (and empty test classes), since they'll be
auto-generated
2013-01-28 18:20:17 +04:00

45 lines
750 B
Kotlin

trait A {
fun foo(): Int
}
class B1 : A {
override fun foo() = 10
}
class B2(val z: Int) : A {
override fun foo() = z
}
fun f1(b: B1): Int {
val o = object : A by b { }
return o.foo()
}
fun f2(b: B2): Int {
val o = object : A by B2(b.z) { }
return o.foo()
}
fun f3(b: B2, mult: Int): Int {
val o = object : A by B2(mult * b.z) { }
return o.foo()
}
fun f4(b: B1, x: Int, y: Int, z: Int): Int {
val o = object : A by b {
fun bar() = x + y + z
}
return o.foo()
}
fun box(): String {
if (f1(B1()) != 10) return "fail #1"
if (f2(B2(239)) != 239) return "fail #2"
if (f3(B2(239), 2) != 239*2) return "fail #3"
if (f4(B1(), 1, 2, 3) != 10) return "fail #4"
return "OK"
}