Move everything under kotlin-native folder
I was forced to manually do update the following files, because otherwise they would be ignored according .gitignore settings. Probably they should be deleted from repo. Interop/.idea/compiler.xml Interop/.idea/gradle.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml Interop/.idea/modules.xml Interop/.idea/modules/Indexer/Indexer.iml Interop/.idea/modules/Runtime/Runtime.iml Interop/.idea/modules/StubGenerator/StubGenerator.iml backend.native/backend.native.iml backend.native/bc.frontend/bc.frontend.iml backend.native/cli.bc/cli.bc.iml backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt backend.native/tests/link/lib/foo.kt backend.native/tests/link/lib/foo2.kt backend.native/tests/teamcity-test.property
This commit is contained in:
@@ -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,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,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,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,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,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()
|
||||
}
|
||||
@@ -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,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,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,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,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,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,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,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,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,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,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())
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
@@ -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() {
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
|
||||
@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).hashCode()
|
||||
}
|
||||
}
|
||||
println(acc)
|
||||
|
||||
acc = 0
|
||||
for (i in Byte.MIN_VALUE..Byte.MAX_VALUE) {
|
||||
acc += areSame(i, i).hashCode()
|
||||
}
|
||||
println(acc)
|
||||
|
||||
acc = 0
|
||||
for (i in Short.MIN_VALUE..Short.MAX_VALUE) {
|
||||
acc += areSame(i, i).hashCode()
|
||||
}
|
||||
println(acc)
|
||||
|
||||
acc = 0
|
||||
for (i in 0.toChar()..range.toChar()) {
|
||||
acc += areSame(i, i).hashCode()
|
||||
}
|
||||
println(acc)
|
||||
|
||||
acc = 0
|
||||
for (i in -range..range) {
|
||||
acc += areSame(i, i).hashCode()
|
||||
}
|
||||
println(acc)
|
||||
|
||||
acc = 0
|
||||
for (i in -range.toLong()..range.toLong()) {
|
||||
acc += areSame(i, i).hashCode()
|
||||
}
|
||||
println(acc)
|
||||
}
|
||||
@@ -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.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)
|
||||
}
|
||||
|
||||
@@ -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.boxing1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(arg: Any) {
|
||||
println(arg.toString())
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(1)
|
||||
foo(false)
|
||||
foo("Hello")
|
||||
}
|
||||
@@ -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,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,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.boxing12
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(x: Number) {
|
||||
println(x.toByte())
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(18)
|
||||
}
|
||||
@@ -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.boxing.boxing13
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun is42(x: Any?) {
|
||||
println(x == 42)
|
||||
println(42 == x)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
is42(16)
|
||||
is42(42)
|
||||
is42("42")
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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()
|
||||
}
|
||||
|
||||
fun <T> T.println() = println(this.toString())
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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))
|
||||
}
|
||||
|
||||
fun <T : Int> foo(x: T): Int = x
|
||||
@@ -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.boxing.boxing2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun printInt(x: Int) = println(x)
|
||||
fun printBoolean(x: Boolean) = println(x)
|
||||
|
||||
fun foo(arg: Any) {
|
||||
if (arg is Int)
|
||||
printInt(arg)
|
||||
else if (arg is Boolean)
|
||||
printBoolean(arg)
|
||||
else
|
||||
println("other")
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(1)
|
||||
foo(true)
|
||||
foo("Hello")
|
||||
}
|
||||
@@ -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.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)
|
||||
}
|
||||
@@ -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.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)
|
||||
}
|
||||
@@ -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.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)
|
||||
}
|
||||
@@ -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.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")
|
||||
}
|
||||
@@ -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.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")
|
||||
}
|
||||
@@ -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.boxing8
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(vararg args: Any?) {
|
||||
for (arg in args) {
|
||||
println(arg.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(1, null, true, "Hello")
|
||||
}
|
||||
@@ -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,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()
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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,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,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.when_through
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun when_through(i: Int): Int {
|
||||
var value = 1
|
||||
when (i) {
|
||||
10 -> value = 42
|
||||
11 -> value = 43
|
||||
12 -> value = 44
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (when_through(2) != 1) throw Error()
|
||||
}
|
||||
@@ -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.branching.when_with_try1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
println(foo(Any()))
|
||||
println(foo("zzz"))
|
||||
println(foo("42"))
|
||||
}
|
||||
|
||||
fun foo(value: Any): Int? {
|
||||
if (value is CharSequence) {
|
||||
try {
|
||||
return value.toString().toInt()
|
||||
} catch (e: NumberFormatException) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
sealed class Tag {
|
||||
abstract fun value(): Any
|
||||
}
|
||||
|
||||
sealed class TagBoolean : Tag() {
|
||||
abstract override fun value(): Boolean
|
||||
|
||||
object True : TagBoolean() {
|
||||
override fun value() = true
|
||||
}
|
||||
|
||||
object False : TagBoolean() {
|
||||
override fun value() = false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val test: TagBoolean = TagBoolean.True
|
||||
println(test.value())
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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 a
|
||||
|
||||
interface A<T> {
|
||||
fun foo(): T
|
||||
}
|
||||
|
||||
open class C: A<Int> {
|
||||
override fun foo(): Int = 42
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
import a.*
|
||||
|
||||
class B: C()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val b = B()
|
||||
println(b.foo())
|
||||
val c: C = b
|
||||
println(c.foo())
|
||||
val a: A<Int> = b
|
||||
println(a.foo())
|
||||
}
|
||||
@@ -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.bridges.nativePointed
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import kotlin.test.*
|
||||
|
||||
abstract class C {
|
||||
abstract fun foo(x: Int): CPointer<*>?
|
||||
}
|
||||
|
||||
class CImpl : C() {
|
||||
override fun foo(x: Int) = null
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val c: C = CImpl()
|
||||
assertNull(c.foo(42))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.bridges.signature
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A { }
|
||||
|
||||
class B { }
|
||||
|
||||
class C { }
|
||||
|
||||
interface Parser<in IN: Any, out OUT: Any> {
|
||||
fun parse(source: IN): OUT
|
||||
}
|
||||
|
||||
interface MultiParser<in IN: Any, out OUT: Any> {
|
||||
fun parse(source: IN): Collection<OUT>
|
||||
}
|
||||
|
||||
interface ExtendsInterface<T: Any>: Parser<A, T>, MultiParser<B, T> {
|
||||
override fun parse(source: B): Collection<T> = ArrayList<T>()
|
||||
}
|
||||
|
||||
abstract class AbstractClass(): ExtendsInterface<C> {
|
||||
public override fun parse(source: A): C = C()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val array = object : AbstractClass() { }.parse(B())
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.bridges.special
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
private object NotEmptyMap : MutableMap<Any, Int> {
|
||||
override fun containsKey(key: Any): Boolean = true
|
||||
override fun containsValue(value: Int): Boolean = true
|
||||
|
||||
// non-special bridges get(Object)Integer -> get(Object)I
|
||||
override fun get(key: Any): Int = 1
|
||||
override fun remove(key: Any): Int = 1
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
override fun put(key: Any, value: Int): Int? = throw UnsupportedOperationException()
|
||||
override fun putAll(from: Map<out Any, Int>): Unit = throw UnsupportedOperationException()
|
||||
override fun clear(): Unit = throw UnsupportedOperationException()
|
||||
override val entries: MutableSet<MutableMap.MutableEntry<Any, Int>> get() = null!!
|
||||
override val keys: MutableSet<Any> get() = null!!
|
||||
override val values: MutableCollection<Int> get() = null!!
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val n = NotEmptyMap as MutableMap<Any?, Any?>
|
||||
|
||||
if (n.get(null) != null) return "fail 1"
|
||||
if (n.containsKey(null)) return "fail 2"
|
||||
if (n.containsValue(null)) return "fail 3"
|
||||
if (n.remove(null) != null) return "fail 4"
|
||||
|
||||
if (n.get(1) == null) return "fail 5"
|
||||
if (!n.containsKey("")) return "fail 6"
|
||||
if (!n.containsValue(3)) return "fail 7"
|
||||
if (n.remove("") == null) return "fail 8"
|
||||
|
||||
return "Ok"
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -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.bridges.test0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// vtable call
|
||||
open class A {
|
||||
open fun foo(): Any = "A"
|
||||
}
|
||||
|
||||
open class C : A() {
|
||||
override fun foo(): Int = 42
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val c = C()
|
||||
val a: A = c
|
||||
println(c.foo().toString())
|
||||
println(a.foo().toString())
|
||||
}
|
||||
@@ -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.bridges.test1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// interface call, bridge overridden
|
||||
interface Z1 {
|
||||
fun foo(x: Int) : Any
|
||||
}
|
||||
|
||||
open class A : Z1 {
|
||||
override fun foo(x: Int) : Int = 5
|
||||
}
|
||||
|
||||
open class B : A() {
|
||||
override fun foo(x: Int) : Int = 42
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val z1: A = B()
|
||||
println((z1.foo(1) + 1000).toString())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.bridges.test10
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class A<T> {
|
||||
open fun foo(x: T) {
|
||||
println(x.toString())
|
||||
}
|
||||
}
|
||||
|
||||
interface I {
|
||||
fun foo(x: Int)
|
||||
}
|
||||
|
||||
class B : A<Int>(), I {
|
||||
var z: Int = 5
|
||||
override fun foo(x: Int) {
|
||||
z = x
|
||||
}
|
||||
}
|
||||
|
||||
fun zzz(a: A<Int>) {
|
||||
a.foo(42)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val b = B()
|
||||
zzz(b)
|
||||
val a = A<Int>()
|
||||
zzz(a)
|
||||
println(b.z)
|
||||
}
|
||||
@@ -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.bridges.test11
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface I {
|
||||
fun foo(x: Int)
|
||||
}
|
||||
|
||||
abstract class A<T> {
|
||||
abstract fun foo(x: T)
|
||||
}
|
||||
|
||||
class B : A<Int>(), I {
|
||||
override fun foo(x: Int) = println(x)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val b = B()
|
||||
val a: A<Int> = b
|
||||
val c: I = b
|
||||
b.foo(42)
|
||||
a.foo(42)
|
||||
c.foo(42)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.bridges.test12
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
abstract class A<in T> {
|
||||
abstract fun foo(x: T)
|
||||
}
|
||||
|
||||
class B : A<Int>() {
|
||||
override fun foo(x: Int) {
|
||||
println("B: $x")
|
||||
}
|
||||
}
|
||||
|
||||
class C : A<Any>() {
|
||||
override fun foo(x: Any) {
|
||||
println("C: $x")
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(arg: A<Int>) {
|
||||
arg.foo(42)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(B())
|
||||
foo(C())
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.bridges.test13
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class A<T> {
|
||||
open fun T.foo() {
|
||||
println(this.toString())
|
||||
}
|
||||
|
||||
fun bar(x: T) {
|
||||
x.foo()
|
||||
}
|
||||
}
|
||||
|
||||
open class B: A<Int>() {
|
||||
override fun Int.foo() {
|
||||
println(this)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val b = B()
|
||||
val a = A<Int>()
|
||||
b.bar(42)
|
||||
a.bar(42)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.bridges.test14
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class A<T, U> {
|
||||
open fun foo(x: T, y: U) {
|
||||
println(x.toString())
|
||||
println(y.toString())
|
||||
}
|
||||
}
|
||||
|
||||
interface I1<T> {
|
||||
fun foo(x: Int, y: T)
|
||||
}
|
||||
|
||||
interface I2<T> {
|
||||
fun foo(x: T, y: Int)
|
||||
}
|
||||
|
||||
class B : A<Int, Int>(), I1<Int>, I2<Int> {
|
||||
var z: Int = 5
|
||||
var q: Int = 7
|
||||
override fun foo(x: Int, y: Int) {
|
||||
z = x
|
||||
q = y
|
||||
}
|
||||
}
|
||||
|
||||
fun zzz(a: A<Int, Int>) {
|
||||
a.foo(42, 56)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val b = B()
|
||||
zzz(b)
|
||||
val a = A<Int, Int>()
|
||||
zzz(a)
|
||||
println(b.z)
|
||||
println(b.q)
|
||||
val i1: I1<Int> = b
|
||||
i1.foo(56, 42)
|
||||
println(b.z)
|
||||
println(b.q)
|
||||
val i2: I2<Int> = b
|
||||
i2.foo(156, 142)
|
||||
println(b.z)
|
||||
println(b.q)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.bridges.test15
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// non-generic interface, generic impl, vtable call + interface call
|
||||
open class A<T> {
|
||||
open var size: T = 56 as T
|
||||
}
|
||||
|
||||
interface C {
|
||||
var size: Int
|
||||
}
|
||||
|
||||
open class B : C, A<Int>()
|
||||
|
||||
open class D: B() {
|
||||
override var size: Int = 117
|
||||
}
|
||||
|
||||
fun <T> foo(a: A<T>) {
|
||||
a.size = 42 as T
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
|
||||
foo(b)
|
||||
if (b.size != 42) return "fail 1"
|
||||
val d = D()
|
||||
if (d.size != 117) return "fail 2"
|
||||
foo(d)
|
||||
if (d.size != 42) return "fail 3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -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.bridges.test16
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
abstract class C: A
|
||||
|
||||
open class B: C() {
|
||||
override fun foo(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(c: C) = c.foo()
|
||||
|
||||
@Test fun runTest() {
|
||||
val b = B()
|
||||
val c: C = b
|
||||
println(bar(b))
|
||||
println(bar(c))
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.bridges.test17
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// abstract bridge
|
||||
interface A<T> {
|
||||
fun foo(): T
|
||||
}
|
||||
|
||||
abstract class B<T>: A<T>
|
||||
|
||||
abstract class C: B<Int>()
|
||||
|
||||
class D: C() {
|
||||
override fun foo(): Int {
|
||||
return 42
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val d = D()
|
||||
val c: C = d
|
||||
val b: B<Int> = d
|
||||
val a: A<Int> = d
|
||||
println(d.foo())
|
||||
println(c.foo())
|
||||
println(b.foo())
|
||||
println(a.foo())
|
||||
}
|
||||
@@ -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.bridges.test18
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// overriden function returns Unit
|
||||
open class A {
|
||||
open fun foo(): Any = 42
|
||||
}
|
||||
|
||||
open class B: A() {
|
||||
override fun foo(): Unit { }
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val a: A = B()
|
||||
println(a.foo())
|
||||
}
|
||||
@@ -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.bridges.test2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// vtable call, bridge inherited
|
||||
open class A {
|
||||
open fun foo(): Any = "A"
|
||||
}
|
||||
|
||||
open class C : A() {
|
||||
override fun foo(): Int = 42
|
||||
}
|
||||
|
||||
open class D: C()
|
||||
|
||||
@Test fun runTest() {
|
||||
val c = D()
|
||||
val a: A = c
|
||||
println(c.foo().toString())
|
||||
println(a.foo().toString())
|
||||
}
|
||||
@@ -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.bridges.test3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// non-generic interface, generic impl, non-virtual call + interface call
|
||||
open class A<T> {
|
||||
var size: T = 56 as T
|
||||
}
|
||||
|
||||
interface C {
|
||||
var size: Int
|
||||
}
|
||||
|
||||
class B : C, A<Int>()
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
if (b.size != 56) return "fail 1"
|
||||
|
||||
b.size = 55
|
||||
if (b.size != 55) return "fail 2"
|
||||
|
||||
val c: C = b
|
||||
if (c.size != 55) return "fail 3"
|
||||
|
||||
c.size = 57
|
||||
if (c.size != 57) return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.bridges.test4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// vtable call + interface call
|
||||
interface Z {
|
||||
fun foo(): Any
|
||||
}
|
||||
|
||||
interface Y {
|
||||
fun foo(): Int
|
||||
}
|
||||
|
||||
open class A {
|
||||
fun foo(): Int = 42
|
||||
}
|
||||
|
||||
open class B: A(), Z, Y
|
||||
|
||||
@Test fun runTest() {
|
||||
val z: Z = B()
|
||||
val y: Y = z as Y
|
||||
println(z.foo().toString())
|
||||
println(y.foo().toString())
|
||||
}
|
||||
@@ -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.bridges.test5
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// non-generic interface, generic impl, vtable call + interface call
|
||||
open class A<T> {
|
||||
open var size: T = 56 as T
|
||||
}
|
||||
|
||||
interface C {
|
||||
var size: Int
|
||||
}
|
||||
|
||||
open class B : C, A<Int>()
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
if (b.size != 56) return "fail 1"
|
||||
|
||||
b.size = 55
|
||||
if (b.size != 55) return "fail 2"
|
||||
|
||||
val c: C = b
|
||||
if (c.size != 55) return "fail 3"
|
||||
|
||||
c.size = 57
|
||||
if (c.size != 57) return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -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.bridges.test6
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// vtable call + interface call
|
||||
interface Z {
|
||||
fun foo(): Any
|
||||
}
|
||||
|
||||
interface Y {
|
||||
fun foo(): Int
|
||||
}
|
||||
|
||||
open class A {
|
||||
open fun foo(): Any = "A"
|
||||
}
|
||||
|
||||
open class C : A() {
|
||||
override fun foo(): Int = 42
|
||||
}
|
||||
|
||||
open class D: C(), Y, Z
|
||||
|
||||
@Test fun runTest() {
|
||||
val d = D()
|
||||
val y: Y = d
|
||||
val z: Z = d
|
||||
val c: C = d
|
||||
val a: A = d
|
||||
println(d.foo().toString())
|
||||
println(y.foo().toString())
|
||||
println(z.foo().toString())
|
||||
println(c.foo().toString())
|
||||
println(a.foo().toString())
|
||||
}
|
||||
@@ -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.bridges.test7
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// generic interface, non-generic impl, vtable call + interface call
|
||||
open class A {
|
||||
open var size: Int = 56
|
||||
}
|
||||
|
||||
interface C<T> {
|
||||
var size: T
|
||||
}
|
||||
|
||||
open class B : C<Int>, A()
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
if (b.size != 56) return "fail 1"
|
||||
|
||||
b.size = 55
|
||||
if (b.size != 55) return "fail 2"
|
||||
|
||||
val c: C<Int> = b
|
||||
if (c.size != 55) return "fail 3"
|
||||
|
||||
c.size = 57
|
||||
if (c.size != 57) return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -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.bridges.test8
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// generic interface, non-generic impl, non-virtual call + interface call
|
||||
open class A {
|
||||
var size: Int = 56
|
||||
}
|
||||
|
||||
interface C<T> {
|
||||
var size: T
|
||||
}
|
||||
|
||||
class B : C<Int>, A()
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
if (b.size != 56) return "fail 1"
|
||||
|
||||
b.size = 55
|
||||
if (b.size != 55) return "fail 2"
|
||||
|
||||
val c: C<Int> = b
|
||||
if (c.size != 55) return "fail 3"
|
||||
|
||||
c.size = 57
|
||||
if (c.size != 57) return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.bridges.test9
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// abstract class vtable call
|
||||
abstract class A {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
abstract class B : A()
|
||||
|
||||
class Z : B() {
|
||||
override fun foo() = "Z"
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val z = Z()
|
||||
val b: B = z
|
||||
val a: A = z
|
||||
return when {
|
||||
z.foo() != "Z" -> "Fail #1"
|
||||
b.foo() != "Z" -> "Fail #2"
|
||||
a.foo() != "Z" -> "Fail #3"
|
||||
else -> "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.classDelegation.generic
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class Content() {
|
||||
override fun toString() = "OK"
|
||||
}
|
||||
|
||||
interface Box<E> {
|
||||
fun get(): E
|
||||
}
|
||||
|
||||
interface ContentBox<T : Content> : Box<T>
|
||||
|
||||
object Impl : ContentBox<Content> {
|
||||
override fun get(): Content = Content()
|
||||
}
|
||||
|
||||
class ContentBoxDelegate<T : Content>() : ContentBox<T> by (Impl as ContentBox<T>)
|
||||
|
||||
fun box() = ContentBoxDelegate<Content>().get().toString()
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -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 zzz
|
||||
|
||||
interface I {
|
||||
fun foo(): Int
|
||||
}
|
||||
|
||||
open class A : I {
|
||||
override fun foo() = 42
|
||||
}
|
||||
|
||||
open class B : I by A() {
|
||||
val x = 117
|
||||
val y = "zzz"
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
import zzz.*
|
||||
|
||||
class C : B() {
|
||||
val a = "qxx"
|
||||
val b = 123
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val c = C()
|
||||
println(c.a)
|
||||
println(c.b)
|
||||
println(c.foo())
|
||||
println(c.x)
|
||||
println(c.y)
|
||||
}
|
||||
@@ -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.classDelegation.method
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A<T> {
|
||||
fun foo(): T
|
||||
}
|
||||
|
||||
class B : A<String> {
|
||||
override fun foo() = "OK"
|
||||
}
|
||||
|
||||
class C(a: A<String>) : A<String> by a
|
||||
|
||||
fun box(): String {
|
||||
val c = C(B())
|
||||
val a: A<String> = c
|
||||
return c.foo() + a.foo()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -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.classDelegation.property
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A {
|
||||
val x: Int
|
||||
}
|
||||
|
||||
class C: A {
|
||||
override val x: Int = 42
|
||||
}
|
||||
|
||||
class Q(a: A): A by a
|
||||
|
||||
fun box(): String {
|
||||
val q = Q(C())
|
||||
val a: A = q
|
||||
return q.x.toString() + a.x.toString()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.classDelegation.withBridge
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A<T> {
|
||||
fun foo(t: T): String
|
||||
}
|
||||
|
||||
interface B {
|
||||
fun foo(t: Int) = "B"
|
||||
}
|
||||
|
||||
class Z : B
|
||||
|
||||
class Z1 : A<Int>, B by Z()
|
||||
|
||||
fun box(): String {
|
||||
val z1 = Z1()
|
||||
val z1a: A<Int> = z1
|
||||
val z1b: B = z1
|
||||
|
||||
return when {
|
||||
z1.foo( 0) != "B" -> "Fail #1"
|
||||
z1a.foo( 0) != "B" -> "Fail #2"
|
||||
z1b.foo( 0) != "B" -> "Fail #3"
|
||||
else -> "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import kotlin.test.*
|
||||
import kotlin.contracts.*
|
||||
|
||||
open class S
|
||||
class P(val str: String = "P") : S()
|
||||
|
||||
@OptIn(kotlin.contracts.ExperimentalContracts::class)
|
||||
fun check(actual: Boolean) {
|
||||
contract { returns() implies actual }
|
||||
assertTrue(actual)
|
||||
}
|
||||
|
||||
@Test fun testContractForCast() {
|
||||
val s: S = P()
|
||||
|
||||
check(s is P)
|
||||
assertEquals(s.str, "P")
|
||||
}
|
||||
|
||||
@Test fun testRequire() {
|
||||
val s: S = P()
|
||||
|
||||
require(s is P)
|
||||
assertEquals(s.str, "P")
|
||||
}
|
||||
|
||||
@Test fun testNonNullSmartCast() {
|
||||
val i: Int? = 1234
|
||||
requireNotNull(i)
|
||||
assertEquals(i, 1234)
|
||||
}
|
||||
|
||||
@Test fun testRunLambdaForVal() {
|
||||
val x: Int
|
||||
run {
|
||||
x = 42
|
||||
}
|
||||
assertEquals(x, 42)
|
||||
}
|
||||
|
||||
@Test fun testIsNullString() {
|
||||
assertEquals("STR", nullableString("str"))
|
||||
|
||||
assertEquals("", nullableString(null))
|
||||
}
|
||||
|
||||
private fun nullableString(string: String?): String = if (string.isNullOrBlank()) "" else "STR"
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.controlflow.`break`
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo() {
|
||||
var i = 0
|
||||
l1@while (true) {
|
||||
println("foo@l1")
|
||||
try {
|
||||
l2@while (true) {
|
||||
if ((i++ % 2) == 0) continue@l2
|
||||
println("foo@l2")
|
||||
if (i > 4) break@l1
|
||||
}
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
var i = 0
|
||||
l1@do {
|
||||
try {
|
||||
println("bar@l1")
|
||||
throw Exception()
|
||||
} catch (e: Exception) {
|
||||
l2@do {
|
||||
if ((i++ % 2) == 0) continue@l2
|
||||
println("bar@l2")
|
||||
if (i > 4) break@l1
|
||||
} while (true)
|
||||
}
|
||||
} while (true)
|
||||
}
|
||||
|
||||
fun qux() {
|
||||
l1@for (i in 1..6) {
|
||||
t1@try {
|
||||
println("qux@t1")
|
||||
throw Exception()
|
||||
}
|
||||
finally {
|
||||
l2@ for (j in 1..6) {
|
||||
if ((j % 2) == 0) continue@l2
|
||||
println("qux@l2")
|
||||
if (j > 4) break@l1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo()
|
||||
bar()
|
||||
qux()
|
||||
}
|
||||
@@ -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.controlflow.break1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
loop@ while (true) {
|
||||
println("Body")
|
||||
break
|
||||
}
|
||||
println("Done")
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.controlflow.for_loops
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
|
||||
// Simple loops
|
||||
for (i in 0..4) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
|
||||
for (i in 0 until 4) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
|
||||
for (i in 4 downTo 0) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
println()
|
||||
|
||||
// Steps
|
||||
for (i in 0..4 step 2) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
|
||||
for (i in 0 until 4 step 2) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
|
||||
for (i in 4 downTo 0 step 2) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
println()
|
||||
|
||||
|
||||
// Two steps
|
||||
for (i in 0..6 step 2 step 3) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
|
||||
for (i in 0 until 6 step 2 step 3) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
|
||||
for (i in 6 downTo 0 step 2 step 3) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
println()
|
||||
|
||||
// Without constants
|
||||
val a = 0
|
||||
val b = 4
|
||||
val s = 2
|
||||
for (i in a..b step s) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
|
||||
for (i in a until b step s) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
|
||||
for (i in b downTo a step s) {
|
||||
print(i)
|
||||
}
|
||||
println()
|
||||
println()
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package codegen.controlflow.for_loops_array
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun <T : ByteArray> genericArray(data : T): Int {
|
||||
var sum = 0
|
||||
for (element in data) {
|
||||
sum += element
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
fun IntArray.sum(): Int {
|
||||
var sum = 0
|
||||
for (element in this) {
|
||||
sum += element
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val intArray = intArrayOf(4, 0, 3, 5)
|
||||
|
||||
val emptyArray = arrayOf<Any>()
|
||||
|
||||
for (element in intArray) {
|
||||
print(element)
|
||||
}
|
||||
println()
|
||||
for (element in emptyArray) {
|
||||
print(element)
|
||||
}
|
||||
println()
|
||||
|
||||
val byteArray = byteArrayOf(1, -1)
|
||||
println(genericArray(byteArray))
|
||||
|
||||
val fives = intArrayOf(5, 5, 5, -5, -5, -5)
|
||||
println(fives.sum())
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package codegen.controlflow.for_loops_array_break_continue
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val intArray = intArrayOf(4, 0, 3, 5)
|
||||
|
||||
val emptyArray = arrayOf<Any>()
|
||||
|
||||
for (element in intArray) {
|
||||
print(element)
|
||||
if (element == 3) {
|
||||
break
|
||||
}
|
||||
}
|
||||
println()
|
||||
for (element in emptyArray) {
|
||||
print(element)
|
||||
}
|
||||
println()
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package codegen.controlflow.for_loops_array_indices
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val intArray = intArrayOf(4, 0, 3, 5)
|
||||
|
||||
val emptyArray = arrayOf<Any>()
|
||||
|
||||
for (index in intArray.indices) {
|
||||
print(index)
|
||||
}
|
||||
println()
|
||||
for (index in emptyArray.indices) {
|
||||
print(index)
|
||||
}
|
||||
println()
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user