Files
kotlin-fork/compiler/testData/codegen/box/ranges/contains/inNonMatchingRange.kt
T
Dmitry Petrov 9d1901fc7c Intrinsify some mismatching range/element combinations for in/in!
It's safe to upcast integer types to Long,
floating-point types to Double.
So we don't have to create a range instance for cases such as

fun testLongInInt(x: Long, a: Int, b: Int) =
    x in a .. b

which is equivalent to

fun testLongInInt(x: Long, a: Int, b: Int) =
    x in a.toLong() .. b.toLong()
2017-07-10 10:51:26 +03:00

55 lines
1.2 KiB
Kotlin
Vendored

// WITH_RUNTIME
fun inInt(x: Long): Boolean {
return x in 1..2
}
fun notInInt(x: Long): Boolean {
return x !in 1..2
}
fun inLong(x: Int): Boolean {
return x in 1L..2L
}
fun notInLong(x: Int): Boolean {
return x !in 1L..2L
}
fun inFloat(x: Double): Boolean {
return x in 1.0f..2.0f
}
fun notInFloat(x: Double): Boolean {
return x !in 1.0f..2.0f
}
fun inDouble(x: Float): Boolean {
return x in 1.0..2.0
}
fun notInDouble(x: Float): Boolean {
return x !in 1.0..2.0
}
fun box(): String {
return when {
!inInt(1L) -> "Fail !inInt"
inInt(0L) -> "Fail inInt"
notInInt(1L) -> "Fail notInInt"
!notInInt(0L) -> "Fail !notInInt"
!inLong(1) -> "Fail !inLong"
inLong(0) -> "Fail inLong"
notInLong(1) -> "Fail notInLong"
!notInLong(0) -> "Fail !notInLong"
!inFloat(1.0) -> "Fain !inFloat"
inFloat(0.0) -> "Fain inFloat"
notInFloat(1.0) -> "Fail notInFloat"
!notInFloat(0.0) -> "Fail !notInFloat"
!inDouble(1.0F) -> "Fail !inDouble"
inDouble(0.0F) -> "Fail inDouble"
notInDouble(1.0F) -> "Fail notInDouble"
!notInDouble(0.0F) -> "Fail !notInDouble"
else -> "OK"
}
}