Ensure type of a stack value is coerced to the expected return type after the binary operation instruction with the different return type.
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
fun box(): String {
|
||||
val a: Long = 2147483647 + 1
|
||||
if (a != -2147483648L) return "fail: in this case we should add to ints and than cast the result to long - overflow expected"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val c1: Char = 0.toChar()
|
||||
val c2 = c1 - 1
|
||||
if (c2 < c1) return "fail: 0.toChar() - 1 should overflow to positive."
|
||||
|
||||
val c3 = c2 + 1
|
||||
if (c3 > c2) return "fail: FFFF.toChar() + 1 should overflow to zero."
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun box(): String {
|
||||
val i1: Int = Int.MAX_VALUE
|
||||
val i2 = i1 + 1
|
||||
if (i2 > i1) return "fail: Int.MAX_VALUE + 1 should overflow to negative."
|
||||
|
||||
val i3: Int = Int.MIN_VALUE
|
||||
val i4 = i3 - 1
|
||||
if (i4 < i3) return "fail: Int.MIN_VALUE - 1 should overflow to positive."
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fun box(): String {
|
||||
val a: Long = 2147483647 + 1
|
||||
if (a != -2147483648L) return "fail: in this case we should add to ints and than cast the result to long - overflow expected"
|
||||
|
||||
val l1 = Long.MAX_VALUE
|
||||
val l2 = l1 + 1
|
||||
if (l2 > l1) return "fail: Long.MAX_VALUE + 1 should overflow to negative."
|
||||
|
||||
val l3 = Long.MIN_VALUE
|
||||
val l4 = l3 - 1
|
||||
if (l4 < l3) return "fail: Long.MIN_VALUE - 1 should overflow to positive."
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user