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
This commit is contained in:
Alexander Udalov
2012-11-27 22:09:57 +04:00
parent 0c5960922a
commit c9bdfd2f07
16 changed files with 261 additions and 22 deletions
@@ -0,0 +1,10 @@
fun checkLess(x: Long, y: Int) = 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(-123456789123.toLong(), 0)