[K/N][Tests] Move some codegen tests to new infra: annotations..coroutines

^KT-61259
This commit is contained in:
Vladimir Sukharev
2023-12-12 13:30:53 +01:00
committed by Space Team
parent a1d13f54cb
commit a5f3d5b737
269 changed files with 2207 additions and 0 deletions
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// FILE: 1.kt
package codegen.annotations.annotations0
import kotlin.test.*
import kotlinx.serialization.*
@SerialInfo
annotation class Foo(val x: Int, val y: String)
@Test fun runTest() {
val foo = @Suppress("ANNOTATION_CLASS_CONSTRUCTOR_CALL") Foo(42, "17")
assertEquals(foo.x, 42)
assertEquals(foo.y, "17")
}
// FILE: 2.kt
package kotlinx.serialization
@Target(AnnotationTarget.ANNOTATION_CLASS)
annotation class SerialInfo
@@ -0,0 +1,96 @@
package codegen.arithmetic.basic
import kotlin.test.*
// Check that compiler doesn't optimize it to `true`
fun selfCmp1(x: Int) = x + 1 > x
fun selfCmp2(x: Int) = x - 1 < x
@Test
fun selfComparison() {
assertFalse(selfCmp1(Int.MAX_VALUE))
assertFalse(selfCmp2(Int.MIN_VALUE))
}
private fun charCornersMinus(): Int {
val a: Char = 0xFFFF.toChar()
val b: Char = 0.toChar()
return a - b
}
private fun charCornersComparison(): Boolean {
val a = 0xFFFF.toChar()
val b = 0.toChar()
return a < b
}
@Test
fun charCornerCases() {
assertEquals(65535, charCornersMinus())
assertFalse(charCornersComparison())
}
@Test
fun shifts() {
assertEquals(-2147483648, 1 shl -1)
assertEquals(0, 1 shr -1)
assertEquals(1, 1 shl 32)
assertEquals(1073741823, -1 ushr 2)
assertEquals(-1, -1 shr 2)
}
@Test
@kotlin.ExperimentalUnsignedTypes
fun uintTests() {
assertEquals(UInt.MAX_VALUE, UInt.MIN_VALUE - 1u)
}
@Test
fun charConversions() {
assertEquals(97.0, 'a'.toDouble())
assertEquals(-1, Char.MAX_VALUE.toShort())
assertEquals(32768, Short.MIN_VALUE.toChar().toInt())
assertEquals(-1, Char.MAX_VALUE.toByte())
assertEquals(65408, Byte.MIN_VALUE.toChar().toInt())
assertEquals(0, Float.MIN_VALUE.toChar().toInt())
}
@Test
fun doubleBasic() {
assertEquals(1, 0f.compareTo(-0f))
assertEquals(1, 0.0.compareTo(-0.0))
assertEquals(1.0, Double.fromBits(1.0.toBits()))
assertEquals(1.0f, Float.fromBits(1.0f.toBits()))
assertEquals(Double.NaN, Double.fromBits((0 / 0.0).toBits()))
assertEquals(Float.NaN, Float.fromBits((0 / 0f).toBits()))
}
@Test
fun integralToFloat() {
assertEquals(9.223372E18f, Long.MAX_VALUE.toFloat())
assertEquals(-9.223372E18f, Long.MIN_VALUE.toFloat())
assertEquals(-2.147483648E9, Int.MIN_VALUE.toDouble())
assertEquals(2.147483647E9, Int.MAX_VALUE.toDouble())
assertEquals(2147483647, Double.MAX_VALUE.toInt())
assertEquals(0, Float.MIN_VALUE.toLong())
assertEquals(9223372036854775807, Float.MAX_VALUE.toLong())
assertEquals(0, Double.MIN_VALUE.toInt())
}
@Test
fun compareIntToFloat() {
assertEquals(1, 0.compareTo(-0.0f))
assertEquals(0, 0.compareTo(+0.0f))
}
@Test
fun testKt37412() {
val two = 2.0
assertEquals(2, two.toInt())
}
@@ -0,0 +1,11 @@
package codegen.arithmetic.division
import kotlin.test.*
@Test
fun divisionByZero() {
assertFailsWith(ArithmeticException::class, { 5 / 0 })
assertFailsWith(ArithmeticException::class, { 5 % 0 })
assertEquals(1, 5 / try { 0 / 0; 1 } catch (e: ArithmeticException) { 5 })
assertEquals(Double.NaN, 0.0 / 0.0)
}
@@ -0,0 +1,26 @@
package codegen.arithmetic.github1856
import kotlin.test.*
object RGBA {
fun packFast(r: Int, g: Int, b: Int, a: Int) = (r shl 0) or (g shl 8) or (b shl 16) or (a shl 24)
fun getFastR(v: Int): Int = (v ushr 0) and 0xFF
fun getFastG(v: Int): Int = (v ushr 8) and 0xFF
fun getFastB(v: Int): Int = (v ushr 16) and 0xFF
fun getFastA(v: Int): Int = (v ushr 24) and 0xFF
fun premultiplyFastInt(v: Int): Int {
val A = getFastA(v) + 1
val RB = (((v and 0x00FF00FF) * A) ushr 8) and 0x00FF00FF
val G = (((v and 0x0000FF00) * A) ushr 8) and 0x0000FF00
return (v and 0x00FFFFFF.inv()) or RB or G
}
}
@Test
fun main() {
val source = listOf(0xFFFFFFFF.toInt(), 0xFFFFFF77.toInt(), 0x777777FF.toInt(), 0x77777777.toInt())
val expect = listOf(-1, -137, 2000107383, 2000107319)
assertEquals(expect, source.map { RGBA.premultiplyFastInt(it) })
}
@@ -0,0 +1,86 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.associatedObjects.associatedObjects1
import kotlin.test.*
import kotlin.reflect.*
@Test
@OptIn(ExperimentalAssociatedObjects::class)
fun testBasics1() {
assertSame(Bar, Foo::class.findAssociatedObject<Associated1>())
assertSame(Baz, Foo::class.findAssociatedObject<Associated2>())
assertSame(null, Foo::class.findAssociatedObject<Associated3>())
assertSame(null, Bar::class.findAssociatedObject<Associated1>())
}
@OptIn(ExperimentalAssociatedObjects::class)
@AssociatedObjectKey
@Retention(AnnotationRetention.BINARY)
annotation class Associated1(val kClass: KClass<*>)
@OptIn(ExperimentalAssociatedObjects::class)
@AssociatedObjectKey
@Retention(AnnotationRetention.BINARY)
annotation class Associated2(val kClass: KClass<*>)
@OptIn(ExperimentalAssociatedObjects::class)
@AssociatedObjectKey
@Retention(AnnotationRetention.BINARY)
annotation class Associated3(val kClass: KClass<*>)
@Associated1(Bar::class)
@Associated2(Baz::class)
class Foo
object Bar
object Baz
@Test
@OptIn(ExperimentalAssociatedObjects::class)
fun testGlobalOptimizations1() {
val i1 = I1ImplHolder::class.findAssociatedObject<Associated1>()!! as I1
assertEquals(42, i1.foo())
val c = C(null)
i1.bar(c)
assertEquals("zzz", c.list!![0])
}
private class C(var list: List<String>?)
private interface I1 {
fun foo(): Int
fun bar(c: C)
}
private object I1Impl : I1 {
override fun foo() = 42
override fun bar(c: C) {
c.list = mutableListOf("zzz")
}
}
@Associated1(I1Impl::class)
private class I1ImplHolder
@Test
@OptIn(ExperimentalAssociatedObjects::class)
fun testGlobalOptimizations2() {
val i2 = I2ImplHolder()::class.findAssociatedObject<Associated1>()!! as I2
assertEquals(17, i2.foo())
}
private interface I2 {
fun foo(): Int
}
private object I2Impl : I2 {
override fun foo() = 17
}
@Associated1(I2Impl::class)
private class I2ImplHolder
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.array_to_any
import kotlin.test.*
@Test
fun runTest() {
foo().hashCode()
}
fun foo(): Any {
return Array<Any?>(0, { i -> null })
}
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.canonical_name
import kotlin.test.*
interface I<U, T> {
fun foo(a: U): T
fun qux(a: T): U
}
//-----------------------------------------------------------------------------//
class A1
class A2
//-----------------------------------------------------------------------------//
class A : I<A1, A2> {
override fun foo(a: A1): A2 { println("A:foo"); return A2() }
override fun qux(a: A2): A1 { println("A:qux"); return A1() }
}
//-----------------------------------------------------------------------------//
fun <U, V> baz(i: I<U, V>, u: U, v:V) {
i.foo(u)
i.qux(v)
}
//-----------------------------------------------------------------------------//
@Test
fun runTest() {
baz<A1, A2>(A(), A1(), A2())
}
@@ -0,0 +1,2 @@
A:foo
A:qux
@@ -0,0 +1,58 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.cast_null
import kotlin.test.*
@Test
fun runTest() {
testCast(null, false)
testCastToNullable(null, true)
testCastToNullable(TestKlass(), true)
testCastToNullable("", false)
testCastNotNullableToNullable(TestKlass(), true)
testCastNotNullableToNullable("", false)
println("Ok")
}
class TestKlass
fun ensure(b: Boolean) {
if (!b) {
println("Error")
}
}
fun testCast(x: Any?, expectSuccess: Boolean) {
try {
x as TestKlass
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
fun testCastToNullable(x: Any?, expectSuccess: Boolean) {
try {
x as TestKlass?
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
fun testCastNotNullableToNullable(x: Any, expectSuccess: Boolean) {
try {
x as TestKlass?
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
@@ -0,0 +1 @@
Ok
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.cast_simple
import kotlin.test.*
open class A() {}
class B(): A() {}
fun castSimple(o: Any) : A = o as A
fun castTest(): Boolean {
val b = B()
castSimple(b)
return true
}
@Test
fun runTest() {
if (!castTest()) throw Error()
}
@@ -0,0 +1,48 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.check_type
import kotlin.test.*
interface I
class A() : I {}
class B() {}
//-----------------------------------------------------------------------------//
fun isTypeOf(a: Any?) : Boolean {
return a is A
}
//-----------------------------------------------------------------------------//
fun isTypeNullableOf(a: Any?) : Boolean {
return a is A?
}
//-----------------------------------------------------------------------------//
fun isNotTypeOf(a: Any) : Boolean {
return a !is A
}
//-----------------------------------------------------------------------------//
fun isTypeOfInterface(a: Any) : Boolean {
return a is I
}
//-----------------------------------------------------------------------------//
@Test
fun runTest() {
println(isTypeOf(A()))
println(isTypeOf(null))
println(isTypeNullableOf(A()))
println(isTypeNullableOf(null))
println(isNotTypeOf(B()))
println(isTypeOfInterface(A()))
}
@@ -0,0 +1,6 @@
true
false
true
true
true
true
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
class A {
companion object {
fun foo() = "comp"
}
}
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.concatenation
import kotlin.test.*
@Test
fun runTest() {
val s = "world"
val i = 1
println("Hello $s $i ${2*i}")
for (item in listOf("a", "b")) {
println("Hello, $item")
}
}
@@ -0,0 +1,3 @@
Hello world 1 2
Hello, a
Hello, b
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.const_infinity
import kotlin.test.*
//Original issue here https://youtrack.jetbrains.com/issue/KT-37212
@Suppress("DIVISION_BY_ZERO")
const val fpInfConst = 1.0F / 0.0F
@Suppress("DIVISION_BY_ZERO")
val fpInfVal = 1.0F / 0.0F
@Test
fun runTest() {
assertEquals(fpInfConst, Float.POSITIVE_INFINITY)
assertEquals(fpInfVal, Float.POSITIVE_INFINITY)
assertEquals(fpInfConst, fpInfVal)
}
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.expression_as_statement
import kotlin.test.*
fun foo() {
Any() as String
}
@Test
fun runTest() {
try {
foo()
} catch (e: Throwable) {
println("Ok")
return
}
println("Fail")
}
@@ -0,0 +1 @@
Ok
+37
View File
@@ -0,0 +1,37 @@
package codegen.basics.k42000_1
import kotlin.test.*
@Test
fun runTest() {
assertTrue(Reproducer().repro() > 0)
}
// Based on https://youtrack.jetbrains.com/issue/KT-42000#focus=Comments-27-4404934.0-0
val Int.isEven get() = this % 2 == 0
inline operator fun <reified T : Number> T.plus(other: T): T = when (T::class) {
Double::class -> (this as Double) + (other as Double)
Int::class -> (this as Int) + (other as Int)
Long::class -> (this as Long) + (other as Long)
else -> TODO()
} as T
inline fun <reified T : Number> Collection<T>.median(): Double {
val sorted = this.sortedBy {
it.toDouble()
}
return if (size.isEven || size == 1) {
sorted[size / 2]
} else {
sorted[size / 2] + sorted[size / 2 + 1]
}.toDouble()
}
class Reproducer {
private var someListOfLongs = mutableListOf<Long>(1L)
fun repro() = someListOfLongs.median()
}
+14
View File
@@ -0,0 +1,14 @@
package codegen.basics.k42000_2
import kotlin.test.*
// https://youtrack.jetbrains.com/issue/KT-42000
@Test
fun runTest() {
assertFailsWith<Error> {
when (1) {
else -> throw Error()
} as String
}
}
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.local_variable
import kotlin.test.*
fun local_variable(a: Int) : Int {
var b = 0
b = a + 11
return b
}
@Test
fun runTest() {
if (local_variable(3) != 14) throw Error()
}
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.null_check
import kotlin.test.*
//--- Test "eqeq" -------------------------------------------------------------//
fun check_eqeq(a: Any?) = a == null
fun null_check_eqeq1() : Boolean {
return check_eqeq(Any())
}
fun null_check_eqeq2() : Boolean {
return check_eqeq(null)
}
//--- Test "eqeqeq" -----------------------------------------------------------//
fun check_eqeqeq(a: Any?) = a === null
fun null_check_eqeqeq1() : Boolean {
return check_eqeqeq(Any())
}
fun null_check_eqeqeq2() : Boolean {
return check_eqeqeq(null)
}
@Test
fun runTest() {
if (null_check_eqeq1()) throw Error()
if (!null_check_eqeq2()) throw Error()
if (null_check_eqeqeq1()) throw Error()
if (!null_check_eqeqeq2()) throw Error()
}
@@ -0,0 +1,32 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.safe_cast
import kotlin.test.*
open class A
class B : A()
class C
fun foo(a: Any) : A? = a as? A
fun safe_cast_positive(): Boolean {
val b = B()
return foo(b) === b
}
fun safe_cast_negative(): Boolean {
val c = C()
return foo(c) == null
}
@Test
fun runTest() {
val safeCastPositive = safe_cast_positive().toString()
val safeCastNegative = safe_cast_negative().toString()
println("safe_cast_positive: " + safeCastPositive)
println("safe_cast_negative: " + safeCastNegative)
}
@@ -0,0 +1,2 @@
safe_cast_positive: true
safe_cast_negative: true
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.spread_operator_0
import kotlin.test.*
@Test
fun runTest() {
val list0 = _arrayOf("K", "o", "t", "l", "i", "n")
val list1 = _arrayOf("l", "a","n", "g", "u", "a", "g", "e")
val list = foo(list0, list1)
println(list.toString())
}
fun foo(a:Array<out String>, b:Array<out String>) = listOf(*a," ", "i", "s", " ", "c", "o", "o", "l", " ", *b)
fun _arrayOf(vararg arg:String) = arg
@@ -0,0 +1 @@
[K, o, t, l, i, n, , i, s, , c, o, o, l, , l, a, n, g, u, a, g, e]
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.superFunCall
import kotlin.test.*
open class C {
open fun f() = "<fun:C>"
}
class C1: C() {
override fun f() = super<C>.f() + "<fun:C1>"
}
open class C2: C() {
}
class C3: C2() {
override fun f() = super<C2>.f() + "<fun:C3>"
}
@Test
fun runTest() {
println(C1().f())
println(C3().f())
}
@@ -0,0 +1,2 @@
<fun:C><fun:C1>
<fun:C><fun:C3>
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.superGetterCall
import kotlin.test.*
open class C {
open val p1 = "<prop:C>"
}
class C1: C() {
override val p1 = super<C>.p1 + "<prop:C1>"
}
open class C2: C() {
}
class C3: C2() {
override val p1 = super<C2>.p1 + "<prop:C3>"
}
@Test
fun runTest() {
println(C1().p1)
println(C3().p1)
}
@@ -0,0 +1,2 @@
<prop:C><prop:C1>
<prop:C><prop:C3>
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.superSetterCall
import kotlin.test.*
open class C {
open var p2 = "<prop:C>"
set(value) { field = "<prop:C>" + value }
}
class C1: C() {
override var p2 = super<C>.p2 + "<prop:C1>"
set(value) {
super<C>.p2 = value
field = "<prop:C1>" + super<C>.p2
}
}
open class C2: C() {
}
class C3: C2() {
override var p2 = super<C2>.p2 + "<prop:C3>"
set(value) {
super<C2>.p2 = value
field = "<prop:C3>" + super<C2>.p2
}
}
@Test
fun runTest() {
val c1 = C1()
val c3 = C3()
c1.p2 = "zzz"
c3.p2 = "zzz"
println(c1.p2)
println(c3.p2)
}
@@ -0,0 +1,2 @@
<prop:C1><prop:C>zzz
<prop:C3><prop:C>zzz
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.typealias1
import kotlin.test.*
@Test
fun runTest() {
println(Bar(42).x)
}
class Foo(val x: Int)
typealias Bar = Foo
@@ -0,0 +1 @@
42
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.unchecked_cast1
import kotlin.test.*
@Test
fun runTest() {
foo<String>("17")
bar<String>("17")
foo<String>(42)
bar<String>(42)
}
fun <T> foo(x: Any?) {
val y = x as T
println(y.toString())
}
fun <T> bar(x: Any?) {
val y = x as? T
println(y.toString())
}
@@ -0,0 +1,4 @@
17
17
42
42
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.unchecked_cast2
import kotlin.test.*
@Test
fun runTest() {
try {
val x = cast<String>(Any())
println(x.length)
} catch (e: Throwable) {
println("Ok")
}
}
fun <T> cast(x: Any?) = x as T
@@ -0,0 +1 @@
Ok
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.unchecked_cast3
import kotlin.test.*
@Test
fun runTest() {
testCast<TestKlass>(TestKlass(), true)
testCast<TestKlass>(null, false)
testCastToNullable<TestKlass>(null, true)
println("Ok")
}
class TestKlass
fun ensure(b: Boolean) {
if (!b) {
println("Error")
}
}
fun <T : Any> testCast(x: Any?, expectSuccess: Boolean) {
try {
x as T
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
fun <T : Any> testCastToNullable(x: Any?, expectSuccess: Boolean) {
try {
x as T?
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
@@ -0,0 +1 @@
Ok
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.unchecked_cast4
import kotlin.test.*
@Test
fun runTest() {
CI1I2().uncheckedCast<CI1I2>()
CI1I2().uncheckedCast<OtherCI1I2>()
assertFailsWith<ClassCastException> {
Any().uncheckedCast<CI1I2>()
}
println("Ok")
}
fun <R : C> Any?.uncheckedCast() where R : I1, R : I2 {
this as R
}
interface I1
interface I2
open class C
class CI1I2 : C(), I1, I2
class OtherCI1I2 : C(), I1, I2
@@ -0,0 +1 @@
Ok
+13
View File
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.unit1
import kotlin.test.*
@Test
fun runTest() {
println(println("First").toString())
}
+2
View File
@@ -0,0 +1,2 @@
First
kotlin.Unit
+18
View File
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.unit2
import kotlin.test.*
@Test
fun runTest() {
val x = foo()
println(x.toString())
}
fun foo() {
return Unit
}
+1
View File
@@ -0,0 +1 @@
kotlin.Unit
+17
View File
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.unit3
import kotlin.test.*
@Test
fun runTest() {
foo(Unit)
}
fun foo(x: Any) {
println(x.toString())
}
+1
View File
@@ -0,0 +1 @@
kotlin.Unit
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.basics.unit4
import kotlin.test.*
@Test
fun runTest() {
for (x in 0 .. 8) {
foo(x, Unit)
}
println("Done")
}
var global = 42
fun foo(x: Int, unit: Unit) {
var local = 5
val y: Unit = when (x) {
0 -> {}
1 -> local = 6
2 -> global = 43
3 -> unit
4 -> Unit
5 -> bar()
6 -> return
7 -> {
5
bar()
}
8 -> {
val z: Any = Unit
z as Unit
}
else -> throw Error()
}
if (y !== Unit) {
println("Fail at x = $x")
}
}
fun bar() {
}
+1
View File
@@ -0,0 +1 @@
Done
@@ -0,0 +1,622 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bce.arraysForLoops
import kotlin.test.*
import kotlin.reflect.KProperty
@Test fun forEachIndexedTest() {
val array = Array(10) { 0 }
assertFailsWith<IndexOutOfBoundsException> {
array.forEachIndexed { index, _ ->
array[index + 1] = 1
}
}
}
@Test fun forEachIndicies() {
val array = Array(10) { 0 }
val array1 = Array(3) { 0 }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array[i + 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array1[i] = 6
}
}
}
@Test fun forUntilSize() {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array[i - 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size + 10) {
array[i] = 6
}
}
}
@Test fun forDownToSize() {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array[i * 2] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array1[i] = 6
}
}
var a = array.size - 1
val b = ++a
val c = b
assertFailsWith<IndexOutOfBoundsException> {
for (i in c downTo 0) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size + 1 downTo 0) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo -1) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size downTo 0) {
array[i] = 6
}
}
}
@Test fun forRangeToSize() {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array[j] = 6
j++
}
}
var length = array.size - 1
length = 2 * length
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..length) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array[i + 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size + 1) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in -1..array.size - 1) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size) {
array[i] = 6
}
}
}
@Test fun forRangeToWithStep() {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array[i - 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size + 1 step 2) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in -1..array.size - 1 step 2) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size step 2) {
array[i] = 6
}
}
}
@Test fun forUntilWithStep() {
val array = CharArray(10) { '0' }
val array1 = CharArray(3) { '0' }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array[j] = '6'
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array[i + 3] = '6'
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array1[i] = '6'
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until (array.size/0.5).toInt() step 2) {
array[i] = '6'
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in -array.size until array.size step 2) {
array[i] = '6'
}
}
}
@Test fun forDownToWithStep() {
val array = UIntArray(10) { 0U }
val array1 = UIntArray(3) { 0U }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0 step 2) {
array[j] = 6U
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 1 step 2) {
array[i + 1] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 1 step 2) {
array1[i] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (array.size / 0.2).toInt() downTo 1 step 2) {
array[i] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo -3 step 2) {
array[i] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size downTo 1 step 2) {
array[i] = 6U
}
}
}
@Test fun forIndiciesWithStep() {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array[i - 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array1[i] = 6
}
}
}
@Test fun forWithIndex() {
val array = Array(10) { 100 }
val array1 = Array(3) { 0 }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[index + 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[value] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((i, v) in (0..array.size + 30 step 2).withIndex()) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((i, v) in (0..array.size).withIndex()) {
array[v] = 8
}
}
}
@Test fun forReversed() {
val array = Array(10) { 100 }
val array1 = Array(3) { 0 }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0..array.size-1).reversed()) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0 until array.size).reversed()) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0..array.size).reversed()) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (array.size downTo 0).reversed()) {
array[i] = 6
}
}
}
fun foo(a: Int, b : Int): Int = a + b * 2
@Test fun bceCases() {
val array = Array(10) { 100 }
val array1 = Array(3) { 0 }
var length = array.size - 1
var sum = 0
array.forEach {
sum += it
}
for (i in array.indices) {
array[i] = 6
}
for (i in 0 until array.size) {
array[i] = 7
}
for (i in array.size - 1 downTo 1) {
array[i] = 7
}
for (it in array) {
sum += it
}
for (i in 0..array.size - 1 step 2) {
array[i] = 7
}
for (i in 0 until array.size step 2) {
array[i] = 7
}
for (i in array.indices step 2) {
array[i] = 6
}
for (i in array.size - 1 downTo 1 step 2) {
array[i] = 7
}
for ((index, value) in array.withIndex()) {
array[index] = 8
}
for ((i, v) in (0..array.size - 1 step 2).withIndex()) {
array[v] = 8
array[i] = 6
}
for (i in array.reversed()) {
sum += i
}
for (i in (0..array.size-1).reversed()) {
array [i] = 10
}
for (i in 0 until array.size) {
array[i] = 7
for (j in 0 until array1.size) {
array1[j] = array[i]
}
}
val size = array.size - 1
val size1 = size
for (i in 0..size1) {
foo(array[i], array[i])
}
for (i in 0..array.size - 2) {
array[i+1] = array[i]
}
}
var needSmallArray = true
class WithGetter() {
val array: Array<Int>
get() = if (needSmallArray)
Array(10) { 100 }
else
Array(100) { 100 }
}
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): Array<Int> {
return if (needSmallArray)
Array(10) { 100 }
else
Array(100) { 100 }
}
}
class WithDelegates {
val array by Delegate()
}
open class Base {
open val array = Array(10) { 100 }
val array1 by Delegate()
}
class Child : Base() {
override val array: Array<Int>
get() = if (needSmallArray)
Array(10) { 100 }
else
Array(100) { 100 }
}
@Test fun withGetter() {
val obj = WithGetter()
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
needSmallArray = false
}
}
}
@Test fun delegatedProperty() {
val obj = WithDelegates()
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
needSmallArray = false
}
}
}
@Test fun inheritance() {
val obj = Child()
val base = Base()
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
needSmallArray = false
}
}
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array1.size-1) {
needSmallArray = true
obj.array1[i] = 6
needSmallArray = false
}
}
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
base.array[i] = 6
needSmallArray = false
}
}
}
val array: Array<Int> = arrayOf(1)
get() = if (needSmallArray) field else arrayOf(1, 2, 3)
@Test fun customeGetter() {
val a = array
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (index in 0 until array.size) {
a[index] = 6
}
}
}
class First(initArray: Array<Int>) {
val array = initArray
}
class Second(initArray: Array<Int>){
val first = First(initArray)
}
class Third(initArray: Array<Int>) {
val second = Second(initArray)
}
@Test fun differentObjects() {
val a = Third(arrayOf(1, 2, 3, 4, 5))
val b = Third(arrayOf(1, 2))
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..a.second.first.array.size-1) {
b.second.first.array[i] = 6
}
}
}
class Foo(size: Int) {
val array = IntArray(size)
}
class Bar {
val smallFoo = Foo(1)
val largeFoo = Foo(10)
val smallArray = smallFoo.array
val largeArray = largeFoo.array
}
@Test fun differentArrays() {
val bar = Bar()
assertFailsWith<IndexOutOfBoundsException> {
for (index in 0 until bar.largeArray.size) {
bar.smallArray[index] = 6
}
}
}
@@ -0,0 +1,58 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.box_cache0
import kotlin.test.*
fun <T> areSame(arg1: T, arg2: T): Boolean {
return arg1 === arg2
}
fun Boolean.oneIfTrueElseZero(): Int {
return if (this) 1 else 0
}
@Test fun runTest() {
var acc = 0
val range = 1000
for (i in arrayOf(false, true)) {
for (j in arrayOf(false, true)) {
acc += areSame(i, j).oneIfTrueElseZero()
}
}
println(acc)
acc = 0
for (i in Byte.MIN_VALUE..Byte.MAX_VALUE) {
acc += areSame(i, i).oneIfTrueElseZero()
}
println(acc)
acc = 0
for (i in Short.MIN_VALUE..Short.MAX_VALUE) {
acc += areSame(i, i).oneIfTrueElseZero()
}
println(acc)
acc = 0
for (i in 0.toChar()..range.toChar()) {
acc += areSame(i, i).oneIfTrueElseZero()
}
println(acc)
acc = 0
for (i in -range..range) {
acc += areSame(i, i).oneIfTrueElseZero()
}
println(acc)
acc = 0
for (i in -range.toLong()..range.toLong()) {
acc += areSame(i, i).oneIfTrueElseZero()
}
println(acc)
}
@@ -0,0 +1,6 @@
2
256
256
256
256
256
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing0
import kotlin.test.*
class Box<T>(t: T) {
var value = t
}
@Test fun runTest() {
val box: Box<Int> = Box<Int>(17)
println(box.value)
val nonConst = 17
val box2: Box<Int> = Box<Int>(nonConst)
println(box2.value)
}
@@ -0,0 +1,2 @@
17
17
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing1
import kotlin.test.*
fun foo(arg: Any) {
println(arg.toString())
}
@Test fun runTest() {
foo(1)
foo(2u)
foo(false)
foo("Hello")
val nonConstInt = 1
val nonConstUInt = 2u
val nonConstBool = false
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstUInt)
foo(nonConstBool)
foo(nonConstString)
}
@@ -0,0 +1,8 @@
1
2
false
Hello
1
2
false
Hello
+18
View File
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing10
import kotlin.test.*
@Test fun runTest() {
val FALSE: Boolean? = false
if (FALSE != null) {
do {
println("Ok")
} while (FALSE)
}
}
@@ -0,0 +1 @@
Ok
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing11
import kotlin.test.*
fun printInt(x: Int) = println(x)
class Foo(val value: Int?) {
fun foo() {
printInt(if (value != null) value else 42)
}
}
@Test fun runTest() {
Foo(17).foo()
Foo(null).foo()
}
@@ -0,0 +1,2 @@
17
42
+18
View File
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing12
import kotlin.test.*
fun foo(x: Number) {
println(x.toByte())
}
@Test fun runTest() {
foo(18)
val nonConst = 18
foo(nonConst)
}
@@ -0,0 +1,2 @@
18
18
+25
View File
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing13
import kotlin.test.*
fun is42(x: Any?) {
println(x == 42)
println(42 == x)
}
@Test fun runTest() {
is42(16)
is42(42)
is42("42")
val nonConst16 = 16
val nonConst42 = 42
val nonConst42String = "42"
is42(nonConst16)
is42(nonConst42)
is42(nonConst42String)
}
@@ -0,0 +1,12 @@
false
false
true
true
false
false
false
false
true
true
false
false
+16
View File
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing14
import kotlin.test.*
@Test fun runTest() {
42.println()
val nonConst = 42
nonConst.println()
}
fun <T> T.println() = println(this.toString())
@@ -0,0 +1,2 @@
42
42
+16
View File
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing15
import kotlin.test.*
@Test fun runTest() {
println(foo(17))
val nonConst = 17
println(foo(nonConst))
}
fun <T : Int> foo(x: T): Int = x
@@ -0,0 +1,2 @@
17
17
+38
View File
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing2
import kotlin.test.*
fun printInt(x: Int) = println(x)
fun printBoolean(x: Boolean) = println(x)
fun printUInt(x: UInt) = println(x)
fun foo(arg: Any) {
if (arg is Int)
printInt(arg)
else if (arg is Boolean)
printBoolean(arg)
else if (arg is UInt)
printUInt(arg)
else
println("other")
}
@Test fun runTest() {
foo(1)
foo(2u)
foo(true)
foo("Hello")
val nonConstInt = 1
val nonConstUInt = 2u
val nonConstBool = true
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstUInt)
foo(nonConstBool)
foo(nonConstString)
}
@@ -0,0 +1,8 @@
1
2
true
other
1
2
true
other
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing3
import kotlin.test.*
fun printInt(x: Int) = println(x)
fun foo(arg: Int?) {
if (arg != null)
printInt(arg)
}
@Test fun runTest() {
foo(42)
val nonConst = 42
foo(nonConst)
}
@@ -0,0 +1,2 @@
42
42
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing4
import kotlin.test.*
fun printInt(x: Int) = println(x)
fun foo(arg: Any?) {
if (arg is Int? && arg != null)
printInt(arg)
}
@Test fun runTest() {
foo(16)
val nonConst = 16
foo(nonConst)
}
@@ -0,0 +1,2 @@
16
16
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing5
import kotlin.test.*
fun printInt(x: Int) = println(x)
fun foo(arg: Int?) {
printInt(arg ?: 16)
}
@Test fun runTest() {
foo(null)
foo(42)
val nonConstNull = null
val nonConstInt = 42
foo(nonConstNull)
foo(nonConstInt)
}
@@ -0,0 +1,4 @@
16
42
16
42
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing6
import kotlin.test.*
fun printInt(x: Int) = println(x)
fun foo(arg: Any) {
printInt(arg as? Int ?: 16)
}
@Test fun runTest() {
foo(42)
foo("Hello")
val nonConstInt = 42
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstString)
}
@@ -0,0 +1,4 @@
42
16
42
16
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing7
import kotlin.test.*
fun printInt(x: Int) = println(x)
fun foo(arg: Any) {
val argAsInt = try {
arg as Int
} catch (e: ClassCastException) {
0
}
printInt(argAsInt)
}
@Test fun runTest() {
foo(1)
foo("Hello")
val nonConstInt = 1
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstString)
}
@@ -0,0 +1,4 @@
1
0
1
0
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing8
import kotlin.test.*
fun foo(vararg args: Any?) {
for (arg in args) {
println(arg.toString())
}
}
@Test fun runTest() {
foo(1, null, true, "Hello")
val nonConstInt = 1
val nonConstNull = null
val nonConstBool = true
val nonConstString = "Hello"
foo(nonConstInt, nonConstNull, nonConstBool, nonConstString)
}
@@ -0,0 +1,8 @@
1
null
true
Hello
1
null
true
Hello
+22
View File
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.boxing9
import kotlin.test.*
fun foo(vararg args: Any?) {
for (arg in args) {
println(arg.toString())
}
}
fun bar(vararg args: Any?) {
foo(1, *args, 2, *args, 3)
}
@Test fun runTest() {
bar(null, true, "Hello")
}
@@ -0,0 +1,9 @@
1
null
true
Hello
2
null
true
Hello
3
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package codegen.boxing.kt53100_casts
import kotlin.test.*
// Reproducer is copied from FloatingPointParser.unaryMinus()
inline fun <reified T> unaryMinus(value: T): T {
return when (value) {
is Float -> -value as T
is Double -> -value as T
else -> throw NumberFormatException()
}
}
@Test fun runTest(){
println(unaryMinus(0.0))
println(unaryMinus(0.0f))
}
@@ -0,0 +1,2 @@
-0.0
-0.0
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.branching.advanced_when2
import kotlin.test.*
fun advanced_when2(i: Int): Int {
var value = 1
when (i) {
10 -> {val v = 42; value = v}
11 -> {val v = 43; value = v}
12 -> {val v = 44; value = v}
}
return value
}
@Test fun runTest() {
if (advanced_when2(10) != 42) throw Error()
}
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.branching.advanced_when5
import kotlin.test.*
fun advanced_when5(i: Int): Int {
when (i) {
0 -> { val v = 42; return v}
1 -> { val v = 42; return v}
2 -> { val v = 42; return v}
3 -> { val v = 42; return v}
4 -> { val v = 42; return v}
else -> return 24
}
}
@Test fun runTest() {
if (advanced_when5(5) != 24) throw Error()
}
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.branching.if_else
import kotlin.test.*
fun if_else(b: Boolean): Int {
if (b) return 42
else return 24
}
@Test fun runTest() {
if (if_else(false) != 24) throw Error()
}
+19
View File
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.branching.when2
import kotlin.test.*
fun when2(i: Int): Int {
when (i) {
0 -> return 42
else -> return 24
}
}
@Test fun runTest() {
if (when2(0) != 42) throw Error()
}
+19
View File
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.branching.when4
import kotlin.test.*
fun when5(i: Int): Int {
when (i) {
0 -> return 42
1 -> return 4
2 -> return 3
3 -> return 2
4 -> return 1
}
return 24
}
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.branching.when5
import kotlin.test.*
fun when5(i: Int): Int {
when (i) {
0 -> return 42
1 -> return 4
2 -> return 3
3 -> return 2
4 -> return 1
else -> return 24
}
}
@Test fun runTest() {
if (when5(2) != 3) throw Error()
}
+15
View File
@@ -0,0 +1,15 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.branching.when6
import kotlin.test.*
fun foo() {
}
@Test fun runTest() {
if (true) foo() else foo()
}
+17
View File
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.branching.when7
import kotlin.test.*
@Test fun runTest() {
main(emptyArray())
}
fun main(args: Array<String>) {
val b = args.size < 1
val x = if (b) Any() else throw Error()
}
+15
View File
@@ -0,0 +1,15 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.branching.when8
import kotlin.test.*
@Test fun runTest() {
when (true) {
true -> println("true")
false -> println("false")
}
}
@@ -0,0 +1 @@
true
+19
View File
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.branching.when9
import kotlin.test.*
@Test fun runTest() {
foo(0)
println("Ok")
}
fun foo(x: Int) {
when (x) {
0 -> 0
}
}
@@ -0,0 +1 @@
Ok

Some files were not shown because too many files have changed in this diff Show More