Allow unsigned integers overflow values of corresponding signed numbers

This commit is contained in:
Mikhail Zarechenskiy
2018-05-29 03:00:39 +03:00
parent 0da3ae328e
commit 5b5d9dd5a0
11 changed files with 138 additions and 35 deletions
@@ -0,0 +1,10 @@
// !LANGUAGE: +InlineClasses
// !SKIP_METADATA_VERSION_CHECK
// WITH_UNSIGNED
fun box(): String {
val u1: UByte = 255u
if (u1.toByte().toInt() != -1) return "fail"
return "OK"
}
@@ -0,0 +1,25 @@
// !LANGUAGE: +InlineClasses
// !SKIP_METADATA_VERSION_CHECK
// !DIAGNOSTICS: -UNUSED_PARAMETER
const val u1: UByte = 0xFFu
const val u2: UShort = 0xFFFFu
const val u3: UInt = 0xFFFF_FFFFu
const val u4: ULong = 0xFFFF_FFFF_FFFF_FFFFu
const val u5: ULong = 18446744073709551615u
const val u6 = 0xFFFF_FFFF_FFFF_FFFFu
const val u7 = 18446744073709551615u
val u8: Comparable<*> = 0xFFFF_FFFF_FFFF_FFFFu
fun takeUByte(ubyte: UByte) {}
fun test() {
takeUByte(200u)
takeUByte(255u)
takeUByte(0xFFu)
}
val s1: UByte = <!CONSTANT_EXPECTED_TYPE_MISMATCH!>256u<!>
val s2 = <!INT_LITERAL_OUT_OF_RANGE!>18446744073709551616u<!>
@@ -0,0 +1,14 @@
package
public val s1: kotlin.UByte = 256.toUInt()
public val s2: kotlin.Int
public const val u1: kotlin.UByte = -1.toUByte()
public const val u2: kotlin.UShort = -1.toUShort()
public const val u3: kotlin.UInt = -1.toUInt()
public const val u4: kotlin.ULong = -1.toULong()
public const val u5: kotlin.ULong = -1.toULong()
public const val u6: kotlin.ULong = -1.toULong()
public const val u7: kotlin.ULong = -1.toULong()
public val u8: kotlin.Comparable<*>
public fun takeUByte(/*0*/ ubyte: kotlin.UByte): kotlin.Unit
public fun test(): kotlin.Unit