Files
kotlin-fork/compiler/testData/codegen/operatorConventions/compareTo/comparable.kt
T
Alexander Udalov c9bdfd2f07 Generate compareTo() properly
Take into account:
1) resolved call to compareTo (instead of always calling Comparable's method)
2) types of both caller and callee, when primitive, to avoid wrong casting
(instead of always using caller's type)

 #KT-3078 Fixed
2012-11-28 17:45:38 +04:00

17 lines
402 B
Kotlin

trait A : Comparable<A>
class B(val x: Int) : A {
override fun compareTo(other: A) = x.compareTo((other as B).x)
}
fun checkLess(x: A, y: A) = when {
x >= y -> "Fail $x >= $y"
!(x < y) -> "Fail !($x < $y)"
!(x <= y) -> "Fail !($x <= $y)"
x > y -> "Fail $x > $y"
x.compareTo(y) >= 0 -> "Fail $x.compareTo($y) >= 0"
else -> "OK"
}
fun box() = checkLess(B(0), B(1))