Introduce conversions from signed pure constants to unsigned ones
#KT-24717 In Progress #KT-25996 Open #KT-25997 Open
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
// WITH_UNSIGNED
|
||||
// IGNORE_BACKEND: JS_IR, JVM_IR, JS
|
||||
|
||||
fun takeUByte(u: UByte) = u.toByte()
|
||||
fun takeUShort(u: UShort) = u.toShort()
|
||||
fun takeUInt(u: UInt) = u.toInt()
|
||||
fun takeULong(u: ULong) = u.toLong()
|
||||
|
||||
fun box(): String {
|
||||
val b = takeUByte(200 + 55)
|
||||
if (b != (-1).toByte()) return "Fail 1: $b"
|
||||
|
||||
val s = takeUShort(123)
|
||||
if (s != 123.toShort()) return "Fail 2: $s"
|
||||
|
||||
val i = takeUInt(0xFFFF_FFFF)
|
||||
if (i != -1) return "Fail 3: $i"
|
||||
|
||||
val l = takeULong(0xFFFF_FFFF_FFFF)
|
||||
if (l != 0xFFFF_FFFF_FFFFL) return "Fail 4: $l"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE
|
||||
// !CHECK_TYPE
|
||||
|
||||
// Here we mostly trying to fix behaviour in order to track changes in inference rules for unsigned types later
|
||||
|
||||
fun <T> id(x: T): T = x
|
||||
fun <K> select(x: K, y: K): K = TODO()
|
||||
|
||||
fun takeUByte(u: UByte) {}
|
||||
|
||||
fun foo() {
|
||||
select(1, 1u) checkType { _<Comparable<*>>() }
|
||||
takeUByte(<!TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>id(1)<!>)
|
||||
|
||||
1 <!NONE_APPLICABLE!>+<!> 1u
|
||||
(1u + 1) checkType { _<UInt>() }
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
public fun foo(): kotlin.Unit
|
||||
public fun </*0*/ T> id(/*0*/ x: T): T
|
||||
public fun </*0*/ K> select(/*0*/ x: K, /*1*/ y: K): K
|
||||
public fun takeUByte(/*0*/ u: kotlin.UByte): kotlin.Unit
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun takeUByte(u: UByte) {}
|
||||
fun takeUShort(u: UShort) {}
|
||||
fun takeUInt(u: UInt) {}
|
||||
fun takeULong(u: ULong) {}
|
||||
|
||||
fun takeUBytes(vararg u: UByte) {}
|
||||
|
||||
fun takeNullableUInt(u: UInt?) {}
|
||||
|
||||
fun test() {
|
||||
takeUInt(1 + 2)
|
||||
takeUInt(1.plus(2))
|
||||
takeNullableUInt(4)
|
||||
|
||||
takeUInt(<!TYPE_MISMATCH!>Int.MAX_VALUE * 2L<!>)
|
||||
takeUInt(<!TYPE_MISMATCH!>-1<!>)
|
||||
takeUInt(<!TYPE_MISMATCH!>Int.MAX_VALUE * 2L + 2<!>)
|
||||
|
||||
takeUByte(1)
|
||||
takeUByte(255)
|
||||
takeUByte(<!TYPE_MISMATCH!>1.toByte()<!>)
|
||||
|
||||
takeUShort(1)
|
||||
takeUInt(1)
|
||||
takeULong(1)
|
||||
|
||||
takeULong(<!INT_LITERAL_OUT_OF_RANGE!>18446744073709551615<!>)
|
||||
takeULong(1844674407370955161)
|
||||
takeULong(18446744073709551615u)
|
||||
|
||||
takeUInt(<!INTEGER_OVERFLOW, TYPE_MISMATCH!>Int.MAX_VALUE * 2<!>)
|
||||
takeUInt(4294967294)
|
||||
|
||||
takeUBytes(1, 2, 255, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>256<!>, 0, <!TYPE_MISMATCH!>-1<!>, 40 + 2)
|
||||
|
||||
takeUInt(<!TYPE_MISMATCH!>1.myPlus(2)<!>)
|
||||
|
||||
val localVariable = 42
|
||||
takeUInt(<!TYPE_MISMATCH!>localVariable<!>)
|
||||
|
||||
var localMutableVariable = 42
|
||||
takeUInt(<!TYPE_MISMATCH!>localMutableVariable<!>)
|
||||
|
||||
val localNegativeVariable = -1
|
||||
takeUInt(<!TYPE_MISMATCH!>localNegativeVariable<!>)
|
||||
|
||||
takeUInt(<!TYPE_MISMATCH!>globalVariable<!>)
|
||||
|
||||
takeUInt(<!TYPE_MISMATCH!>constVal<!>)
|
||||
|
||||
takeUInt(<!TYPE_MISMATCH!>globalVariableWithGetter<!>)
|
||||
}
|
||||
|
||||
val globalVariable = 10
|
||||
|
||||
const val constVal = 10
|
||||
|
||||
val globalVariableWithGetter: Int get() = 0
|
||||
|
||||
val prop: UByte = <!CONSTANT_EXPECTED_TYPE_MISMATCH!>255<!>
|
||||
|
||||
fun Int.myPlus(other: Int): Int = this + other
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package
|
||||
|
||||
public const val constVal: kotlin.Int = 10
|
||||
public val globalVariable: kotlin.Int = 10
|
||||
public val globalVariableWithGetter: kotlin.Int
|
||||
public val prop: kotlin.UByte = 255
|
||||
public fun takeNullableUInt(/*0*/ u: kotlin.UInt?): kotlin.Unit
|
||||
public fun takeUByte(/*0*/ u: kotlin.UByte): kotlin.Unit
|
||||
public fun takeUBytes(/*0*/ vararg u: kotlin.UByte /*kotlin.UByteArray*/): kotlin.Unit
|
||||
public fun takeUInt(/*0*/ u: kotlin.UInt): kotlin.Unit
|
||||
public fun takeULong(/*0*/ u: kotlin.ULong): kotlin.Unit
|
||||
public fun takeUShort(/*0*/ u: kotlin.UShort): kotlin.Unit
|
||||
public fun test(): kotlin.Unit
|
||||
public fun kotlin.Int.myPlus(/*0*/ other: kotlin.Int): kotlin.Int
|
||||
Reference in New Issue
Block a user