Fix for KT-12125: Wrong increment/decrement on Byte/Char/Short.MAX_VALUE/MIN_VALUE
#KT-12125 Fixed
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
fun test(i: Int): Int {
|
||||
return i
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var b = Byte.MAX_VALUE
|
||||
b++
|
||||
var result = test(b.toInt())
|
||||
if (result != Byte.MIN_VALUE.toInt()) return "fail 1: $result"
|
||||
|
||||
var s = Short.MIN_VALUE
|
||||
s--
|
||||
result = test(s.toInt())
|
||||
if (result != Short.MAX_VALUE.toInt()) return "fail 2: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fun box(): String {
|
||||
var aByte: Byte? = 0
|
||||
var bByte: Byte = 0
|
||||
|
||||
if (aByte != null) aByte--
|
||||
bByte--
|
||||
if (aByte != bByte) return "Failed post-decrement Byte: $aByte != $bByte"
|
||||
|
||||
if (aByte != null) aByte++
|
||||
bByte++
|
||||
if (aByte != bByte) return "Failed post-increment Byte: $aByte != $bByte"
|
||||
|
||||
aByte = null
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun test(i: Int): Int {
|
||||
return i
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var b = Byte.MAX_VALUE
|
||||
var result = test(b.inc().toInt())
|
||||
if (result != Byte.MIN_VALUE.toInt()) return "fail 1: $result"
|
||||
|
||||
var s = Short.MAX_VALUE
|
||||
result = test(s.inc().toInt())
|
||||
if (result != Short.MIN_VALUE.toInt()) return "fail 2: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
fun test(i: Int): Int {
|
||||
return i
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var aByte: Byte? = 0
|
||||
var bByte: Byte = 0
|
||||
|
||||
if (aByte != null) {
|
||||
if (aByte.dec() != bByte.dec()) return "Failed post-decrement Byte: ${aByte.dec()} != ${bByte.dec()}"
|
||||
}
|
||||
|
||||
if (aByte != null) {
|
||||
if (aByte.inc() != bByte.inc()) return "Failed post-increment Byte: ${aByte.inc()} != ${bByte.inc()}"
|
||||
}
|
||||
|
||||
aByte = null
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user