Fix signExtend, narrow and convert intrinsics type inference with NI
Make them `inline` for this.
This commit is contained in:
committed by
SvyatoslavScherbina
parent
dc8c9d70c1
commit
8d922ca56d
@@ -31,20 +31,20 @@ external fun bitsToDouble(bits: Long): Double
|
||||
|
||||
// TODO: deprecate.
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_SIGN_EXTEND)
|
||||
external fun <R : Number> Number.signExtend(): R
|
||||
external inline fun <reified R : Number> Number.signExtend(): R
|
||||
|
||||
// TODO: deprecate.
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_NARROW)
|
||||
external fun <R : Number> Number.narrow(): R
|
||||
external inline fun <reified R : Number> Number.narrow(): R
|
||||
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external fun <R : Any> Byte.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external fun <R : Any> Short.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external fun <R : Any> Int.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external fun <R : Any> Long.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external fun <R : Any> UByte.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external fun <R : Any> UShort.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external fun <R : Any> UInt.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external fun <R : Any> ULong.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Byte.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Short.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Int.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Long.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> UByte.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> UShort.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> UInt.convert(): R
|
||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> ULong.convert(): R
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FILE)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
|
||||
@@ -3533,6 +3533,10 @@ interopTest("interop_withSpaces") {
|
||||
}
|
||||
}
|
||||
|
||||
task interop_convert(type: KonanLocalTest) {
|
||||
source = "codegen/intrinsics/interop_convert.kt"
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: This test isn't run automatically
|
||||
task interop_echo_server(type: RunInteropKonanTest) {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package codegen.intrinsics.interop_convert
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
fun convertIntToShortOrNull(i: Int, b: Boolean): Short? = if (b) i.convert() else null
|
||||
fun narrowIntToShortOrNull(i: Int, b: Boolean): Short? = if (b) i.narrow() else null
|
||||
fun signExtendShortToIntOrNull(i: Short, b: Boolean): Int? = if (b) i.signExtend() else null
|
||||
|
||||
@Test
|
||||
fun testNI() {
|
||||
assertNull(convertIntToShortOrNull(0, false))
|
||||
assertEquals(1, convertIntToShortOrNull(1, true))
|
||||
|
||||
assertNull(narrowIntToShortOrNull(2, false))
|
||||
assertEquals(3, narrowIntToShortOrNull(3, true))
|
||||
|
||||
assertNull(signExtendShortToIntOrNull(4, false))
|
||||
assertEquals(5, signExtendShortToIntOrNull(5, true))
|
||||
}
|
||||
Reference in New Issue
Block a user