K2: support implicit integer to unsigned conversions...

with dedicated opt-in language feature and special
annotation or module capability.
Not intended for a general use, solves specific K/N
scenario with interop libs.
#KT-55902 fixed
This commit is contained in:
Ilya Chernikov
2023-02-04 13:21:58 +01:00
committed by Space Team
parent 3e2f8b834c
commit be2a85be71
30 changed files with 581 additions and 29 deletions
@@ -0,0 +1,71 @@
// FILE: signedToUnsignedConversions_annotation.kt
package kotlin.internal
open annotation class ImplicitIntegerCoercion : Annotation {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
}
// FILE: signedToUnsignedConversions_test.kt
@ImplicitIntegerCoercion
const val IMPLICIT_INT: Int
field = 255
get
@ImplicitIntegerCoercion
const val EXPLICIT_INT: Int
field = 255
get
@ImplicitIntegerCoercion
const val LONG_CONST: Long
field = 255L
get
@ImplicitIntegerCoercion
val NON_CONST: Int
field = 255
get
@ImplicitIntegerCoercion
const val BIGGER_THAN_UBYTE: Int
field = 256
get
@ImplicitIntegerCoercion
const val UINT_CONST: UInt
field = 42
get
fun takeUByte(@ImplicitIntegerCoercion u: UByte) {
}
fun takeUShort(@ImplicitIntegerCoercion u: UShort) {
}
fun takeUInt(@ImplicitIntegerCoercion u: UInt) {
}
fun takeULong(@ImplicitIntegerCoercion u: ULong) {
}
fun takeUBytes(@ImplicitIntegerCoercion vararg u: UByte) {
}
fun takeLong(@ImplicitIntegerCoercion l: Long) {
}
fun test() {
takeUByte(u = 255.toUByte())
takeUByte(u = 255.toUByte())
takeUShort(u = 255.toUShort())
takeUShort(u = 256.toUShort())
takeUInt(u = 255.toUInt())
takeULong(u = 255.toULong())
takeUBytes(u = [255.toUByte(), 255.toUByte(), 42B])
}