[K/N][Tests] Move codegen test sources cycles..innerClass
^KT-61259
This commit is contained in:
committed by
Space Team
parent
35d2be25b2
commit
71a834b778
@@ -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.initializers.correctOrder1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class TestClass {
|
||||
val x: Int
|
||||
|
||||
init {
|
||||
x = 42
|
||||
}
|
||||
|
||||
val y = x
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(TestClass().y)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -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.initializers.correctOrder2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class TestClass {
|
||||
val x: Int
|
||||
|
||||
val y = 42
|
||||
|
||||
init {
|
||||
x = y
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(TestClass().x)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
class X(val s: String)
|
||||
|
||||
val x = X("zzz")
|
||||
|
||||
// FILE: lib2.kt
|
||||
class Z(val x: Int)
|
||||
|
||||
val z2 = Z(x.s.length)
|
||||
|
||||
// FILE: main.kt
|
||||
fun main() {
|
||||
println(z2.x)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
3
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
var z1 = false
|
||||
var z2 = false
|
||||
|
||||
// FILE: lib2.kt
|
||||
import kotlin.test.*
|
||||
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
@EagerInitialization
|
||||
val x = foo()
|
||||
|
||||
private fun foo(): Int {
|
||||
z1 = true
|
||||
return 42
|
||||
}
|
||||
|
||||
// Will be initialized since [x]'s initializer calls a function from the file.
|
||||
val y = run { z2 = true; 117 }
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
assertTrue(z1)
|
||||
assertTrue(z2)
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
var z1 = false
|
||||
var z2 = false
|
||||
|
||||
// FILE: lib2.kt
|
||||
import kotlin.test.*
|
||||
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
@EagerInitialization
|
||||
val x = run { z1 = true; 42 }
|
||||
|
||||
// Won't be initialized (cause no function from the file will be called during [x] initialization).
|
||||
val y = run { z2 = true; 117 }
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
assertTrue(z1)
|
||||
assertFalse(z2)
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
@ThreadLocal
|
||||
var z1 = false
|
||||
var z2 = false
|
||||
@ThreadLocal
|
||||
var z3 = false
|
||||
|
||||
// FILE: lib2.kt
|
||||
import kotlin.test.*
|
||||
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
@EagerInitialization
|
||||
@ThreadLocal
|
||||
val x = foo()
|
||||
|
||||
private fun foo(): Int {
|
||||
z1 = true
|
||||
return 42
|
||||
}
|
||||
|
||||
// Both will be initialized since [x]'s initializer calls a function from the file.
|
||||
val y1 = run { z2 = true; 117 }
|
||||
|
||||
@ThreadLocal
|
||||
val y2 = run { z3 = true; 117 }
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
assertTrue(z1)
|
||||
assertTrue(z2)
|
||||
assertTrue(z3)
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
@ThreadLocal
|
||||
var z1 = false
|
||||
var z2 = false
|
||||
@ThreadLocal
|
||||
var z3 = false
|
||||
|
||||
// FILE: lib2.kt
|
||||
import kotlin.test.*
|
||||
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
@EagerInitialization
|
||||
@ThreadLocal
|
||||
val x = run { z1 = true; 42 }
|
||||
|
||||
// Won't be initialized (cause no function from the file will be called during [x] initialization).
|
||||
val y1 = run { z2 = true; 117 }
|
||||
|
||||
@ThreadLocal
|
||||
val y2 = run { z3 = true; 117 }
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
assertTrue(z1)
|
||||
assertFalse(z2)
|
||||
assertFalse(z3)
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
var z = false
|
||||
|
||||
// FILE: lib2.kt
|
||||
import kotlin.test.*
|
||||
|
||||
val x = foo()
|
||||
|
||||
private fun foo(): Int {
|
||||
z = true
|
||||
return 42
|
||||
}
|
||||
|
||||
fun bar() = 117
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
bar()
|
||||
assertTrue(z)
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
import kotlin.test.*
|
||||
|
||||
val x = foo()
|
||||
|
||||
@ThreadLocal
|
||||
val y = bar()
|
||||
|
||||
private fun foo() = 42
|
||||
|
||||
private fun bar(): Int {
|
||||
assertEquals(x, 42)
|
||||
return 117
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
assertEquals(y, 117)
|
||||
}
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
var z = false
|
||||
|
||||
// FILE: lib2.kt
|
||||
import kotlin.test.*
|
||||
|
||||
val x = foo()
|
||||
|
||||
private fun foo(): Int {
|
||||
z = true
|
||||
return 42
|
||||
}
|
||||
|
||||
class C {
|
||||
fun bar() = 117
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
C().bar()
|
||||
assertFalse(z)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
var z = false
|
||||
|
||||
// FILE: lib2.kt
|
||||
val x = foo()
|
||||
|
||||
fun foo(): Int {
|
||||
z = true
|
||||
return 42
|
||||
}
|
||||
|
||||
object Z {
|
||||
fun bar() { }
|
||||
fun baz() = x
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
Z.bar()
|
||||
assertFalse(z)
|
||||
assertEquals(42, Z.baz())
|
||||
assertTrue(z)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) {
|
||||
if (x <= 0) return
|
||||
bar(x)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
inline fun foo(x: Int) {
|
||||
if (x <= 0) return
|
||||
bar(x)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
@file:OptIn(kotlin.ExperimentalStdlibApi::class, kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
package codegen.initializers.static
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.native.internal.*
|
||||
import kotlin.reflect.*
|
||||
import kotlin.native.Platform
|
||||
import kotlin.native.OsFamily
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>) : String {
|
||||
assertTrue(property.isPermanent());
|
||||
assertTrue(property.returnType.isPermanent())
|
||||
return property.name
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
val z by Delegate()
|
||||
}
|
||||
|
||||
fun f() = 5
|
||||
|
||||
@Test fun testPermanent() {
|
||||
val x = typeOf<Map<String, Int>>()
|
||||
assertTrue(x.isPermanent())
|
||||
val a = A()
|
||||
assertTrue(a.z.isPermanent())
|
||||
assertEquals("z", a.z)
|
||||
val t = ::f
|
||||
assertTrue(t.isPermanent())
|
||||
assertEquals(5, t())
|
||||
val z = { 6 }
|
||||
assertTrue(z.isPermanent())
|
||||
assertEquals(6, z())
|
||||
}
|
||||
|
||||
@Test fun testVarargChange() {
|
||||
fun varargGetter(position:Int, vararg x: Int): Int {
|
||||
x[position] *= 5;
|
||||
return x[position]
|
||||
}
|
||||
|
||||
repeat(3) {
|
||||
assertEquals(10, varargGetter(0, 2, 3, 4))
|
||||
assertEquals(10, varargGetter(0, 2, 3, 4))
|
||||
assertEquals(15, varargGetter(1, 2, 3, 4))
|
||||
assertEquals(15, varargGetter(1, 2, 3, 4))
|
||||
assertEquals(20, varargGetter(2, 2, 3, 4))
|
||||
assertEquals(20, varargGetter(2, 2, 3, 4))
|
||||
if (Platform.osFamily != OsFamily.WASM) {
|
||||
assertFailsWith<IndexOutOfBoundsException> { varargGetter(3, 2, 3, 4) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun testArrays() {
|
||||
assertEquals("1, 2, 3", intArrayOf(1, 2, 3).joinToString())
|
||||
assertEquals("4, 5, 6", longArrayOf(4.toLong(), 5.toLong(), 6.toLong()).joinToString())
|
||||
assertEquals("7, 8, 9", shortArrayOf(7.toShort(), 8.toShort(), 9.toShort()).joinToString())
|
||||
assertEquals("10, 11, 12", byteArrayOf(10.toByte(), 11.toByte(), 12.toByte()).joinToString())
|
||||
assertEquals("abc", charArrayOf('a', 'b', 'c').joinToString(""))
|
||||
assertEquals("1.5, 2.5, -3.5", floatArrayOf(1.5f, 2.5f, -3.5f).joinToString())
|
||||
assertEquals("4.5, 5.5, -6.5", doubleArrayOf(4.5, 5.5, -6.5).joinToString())
|
||||
assertEquals("13, 14, 4294967295", uintArrayOf(13u, 14u, 4294967295u).joinToString())
|
||||
assertEquals("15, 16, 17", ulongArrayOf(15.toULong(), 16.toULong(), 17.toULong()).joinToString())
|
||||
assertEquals("18, 19, 40000", ushortArrayOf(18.toUShort(), 19.toUShort(), 40000.toUShort()).joinToString())
|
||||
assertEquals("20, 21, 200", ubyteArrayOf(20.toUByte(), 21.toUByte(), 200.toUByte()).joinToString())
|
||||
|
||||
assertEquals("abc, def, ghi", arrayOf("abc", "def", "ghi").joinToString())
|
||||
assertEquals("1, 2, 3", arrayOf(1, 2, 3).joinToString())
|
||||
assertEquals("4, 5, 6", arrayOf(4.toLong(), 5.toLong(), 6.toLong()).joinToString())
|
||||
assertEquals("7, 8, 9", arrayOf(7.toShort(), 8.toShort(), 9.toShort()).joinToString())
|
||||
assertEquals("10, 11, 12", arrayOf(10.toByte(), 11.toByte(), 12.toByte()).joinToString())
|
||||
assertEquals("abc", arrayOf('a', 'b', 'c').joinToString(""))
|
||||
assertEquals("1.5, 2.5, -3.5", arrayOf(1.5f, 2.5f, -3.5f).joinToString())
|
||||
assertEquals("4.5, 5.5, -6.5", arrayOf(4.5, 5.5, -6.5).joinToString())
|
||||
assertEquals("13, 14, 4294967295", arrayOf(13u, 14u, 4294967295u).joinToString())
|
||||
assertEquals("15, 16, 17", arrayOf(15.toULong(), 16.toULong(), 17.toULong()).joinToString())
|
||||
assertEquals("18, 19, 40000", arrayOf(18.toUShort(), 19.toUShort(), 40000.toUShort()).joinToString())
|
||||
assertEquals("20, 21, 200", arrayOf(20.toUByte(), 21.toUByte(), 200.toUByte()).joinToString())
|
||||
|
||||
assertEquals("abc, 1, 2, 3, 4, a, 1.5, 2.5, 5, 6, 7, 8",
|
||||
arrayOf("abc", 1, 2.toLong(), 3.toShort(), 4.toByte(), 'a', 1.5f, 2.5, 5u, 6.toULong(), 7.toUShort(), 8.toUByte()).joinToString())
|
||||
}
|
||||
|
||||
@Test fun testList() {
|
||||
assertEquals("abc, def, ghi", listOf("abc", "def", "ghi").joinToString())
|
||||
assertEquals("1, 2, 3", listOf(1, 2, 3).joinToString())
|
||||
assertEquals("4, 5, 6", listOf(4.toLong(), 5.toLong(), 6.toLong()).joinToString())
|
||||
assertEquals("7, 8, 9", listOf(7.toShort(), 8.toShort(), 9.toShort()).joinToString())
|
||||
assertEquals("10, 11, 12", listOf(10.toByte(), 11.toByte(), 12.toByte()).joinToString())
|
||||
assertEquals("abc", listOf('a', 'b', 'c').joinToString(""))
|
||||
assertEquals("1.5, 2.5, -3.5", listOf(1.5f, 2.5f, -3.5f).joinToString())
|
||||
assertEquals("4.5, 5.5, -6.5", listOf(4.5, 5.5, -6.5).joinToString())
|
||||
assertEquals("13, 14, 4294967295", listOf(13u, 14u, 4294967295u).joinToString())
|
||||
assertEquals("15, 16, 17", listOf(15.toULong(), 16.toULong(), 17.toULong()).joinToString())
|
||||
assertEquals("18, 19, 40000", listOf(18.toUShort(), 19.toUShort(), 40000.toUShort()).joinToString())
|
||||
assertEquals("20, 21, 200", listOf(20.toUByte(), 21.toUByte(), 200.toUByte()).joinToString())
|
||||
|
||||
assertEquals("abc, 1, 2, 3, 4, a, 1.5, 2.5, 5, 6, 7, 8",
|
||||
listOf("abc", 1, 2.toLong(), 3.toShort(), 4.toByte(), 'a', 1.5f, 2.5, 5u, 6.toULong(), 7.toUShort(), 8.toUByte()).joinToString())
|
||||
}
|
||||
|
||||
@Test fun testKType() {
|
||||
val ktype = typeOf<Map<in String?, out List<*>>?>()
|
||||
assertTrue(ktype.isPermanent())
|
||||
assertEquals("Map", (ktype.classifier as? KClass<*>)?.simpleName)
|
||||
assertSame(Map::class, ktype.classifier)
|
||||
assertTrue(ktype.isMarkedNullable)
|
||||
assertTrue(ktype.arguments.isPermanent())
|
||||
assertEquals(2, ktype.arguments.size)
|
||||
assertSame(KVariance.IN, ktype.arguments[0].variance)
|
||||
assertSame(KVariance.OUT, ktype.arguments[1].variance)
|
||||
|
||||
val arg0type = ktype.arguments[0].type!!
|
||||
assertTrue(arg0type.isPermanent())
|
||||
assertEquals("String", (arg0type.classifier as? KClass<*>)?.simpleName)
|
||||
assertSame(String::class, arg0type.classifier)
|
||||
assertTrue(arg0type.isMarkedNullable)
|
||||
assertTrue(arg0type.arguments.isPermanent())
|
||||
assertTrue(arg0type.arguments.isEmpty())
|
||||
|
||||
val arg1type = ktype.arguments[1].type!!
|
||||
assertTrue(arg1type.isPermanent())
|
||||
assertEquals("List", (arg1type.classifier as? KClass<*>)?.simpleName)
|
||||
assertSame(List::class, arg1type.classifier)
|
||||
assertFalse(arg1type.isMarkedNullable)
|
||||
assertTrue(arg1type.arguments.isPermanent())
|
||||
assertTrue(arg1type.arguments.size == 1)
|
||||
assertSame(null, arg1type.arguments[0].variance)
|
||||
assertSame(null, arg1type.arguments[0].type)
|
||||
}
|
||||
class R<T, U, V, X>
|
||||
interface S
|
||||
|
||||
@Test fun testReifiedKType() {
|
||||
|
||||
inline fun <reified T, U, V> kTypeOf() where V : List<Int>, V : S, U : T = typeOf<R<T, in U, out V, *>>()
|
||||
|
||||
class XX(val x:List<Int>) : List<Int> by x, S
|
||||
|
||||
val type = kTypeOf<List<Int>, ArrayList<Int>, XX>()
|
||||
assertEquals("codegen.initializers.static.R<kotlin.collections.List<kotlin.Int>, in U, out V, *>", type.toString())
|
||||
assertEquals("[T]", (type.arguments[1].type!!.classifier as KTypeParameter).upperBounds.toString())
|
||||
assertEquals("[kotlin.collections.List<kotlin.Int>, codegen.initializers.static.S]",
|
||||
(type.arguments[2].type!!.classifier as KTypeParameter).upperBounds.toString())
|
||||
}
|
||||
|
||||
inline fun invokeAndReturnKClass(block: ()->Boolean) : KClass<*> {
|
||||
try {
|
||||
if (block()) {
|
||||
return Double::class
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
return String::class
|
||||
} finally {
|
||||
return Int::class
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun testConstantObjectInFinally() {
|
||||
for (i in 0..2) {
|
||||
val clazz = invokeAndReturnKClass {
|
||||
when (i) {
|
||||
0 -> true
|
||||
1 -> false
|
||||
else -> TODO("test")
|
||||
}
|
||||
}
|
||||
assertTrue(clazz.isPermanent())
|
||||
assertEquals("kotlin.Int", clazz.qualifiedName)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun testSmallIntIdentity() {
|
||||
val xBool = true
|
||||
val xBoolStatic : Any = false
|
||||
val xBoolDyanmic : Any = !xBool
|
||||
assertSame(xBoolStatic, xBoolDyanmic)
|
||||
|
||||
val xByte = 1.toByte()
|
||||
val xByteStatic : Any = 2.toByte()
|
||||
val xByteDyanmic : Any = (xByte + xByte).toByte()
|
||||
assertSame(xByteStatic, xByteDyanmic)
|
||||
|
||||
val xShort = 1.toShort()
|
||||
val xShortStatic : Any = 2.toShort()
|
||||
val xShortDyanmic : Any = (xShort + xShort).toShort()
|
||||
assertSame(xShortStatic, xShortDyanmic)
|
||||
|
||||
val xInt = 1.toInt()
|
||||
val xIntStatic : Any = 2.toInt()
|
||||
val xIntDyanmic : Any = xInt + xInt
|
||||
assertSame(xIntStatic, xIntDyanmic)
|
||||
|
||||
val xChar = 1.toChar()
|
||||
val xCharStatic : Any = 2.toChar()
|
||||
val xCharDyanmic : Any = (xChar.code + xChar.code).toChar()
|
||||
assertSame(xCharStatic, xCharDyanmic)
|
||||
|
||||
val xLong = 1.toLong()
|
||||
val xLongStatic = 2.toLong()
|
||||
val xLongDyanmic = xLong + xLong
|
||||
assertSame(xLongStatic, xLongDyanmic)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val x = computeX()
|
||||
|
||||
private fun computeX() = 42
|
||||
|
||||
fun baz1() { }
|
||||
|
||||
fun baz2() { }
|
||||
|
||||
// FILE: main.kt
|
||||
fun bar(x: Int) = if (x == 0) error("") else x
|
||||
|
||||
fun foo(x: Int) {
|
||||
try {
|
||||
bar(x)
|
||||
baz1()
|
||||
} catch (t: Throwable) { }
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(x)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = computeY()
|
||||
|
||||
private fun computeY() = 42
|
||||
|
||||
fun baz1() { }
|
||||
|
||||
fun baz2() { }
|
||||
|
||||
// FILE: main.kt
|
||||
fun bar(x: Int) = if (x == 0) error("") else x
|
||||
|
||||
fun foo(x: Int) {
|
||||
try {
|
||||
bar(x)
|
||||
baz1()
|
||||
} catch (t: Throwable) {
|
||||
println(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) = when {
|
||||
x > 0 -> 42
|
||||
bar(x) -> 117
|
||||
else -> -1
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(123)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) {
|
||||
if (x > 0) bar(x)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(-1)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) {
|
||||
var i = 0
|
||||
while (i < x) {
|
||||
bar(i)
|
||||
++i
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) {
|
||||
var i = 0
|
||||
do {
|
||||
if (i == x) break
|
||||
++i
|
||||
} while (bar(i))
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) {
|
||||
var i = 0
|
||||
do {
|
||||
++i
|
||||
if (i > 0) continue
|
||||
bar(i)
|
||||
} while (i < x)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
class X(val s: String)
|
||||
|
||||
val x = X("zzz")
|
||||
|
||||
// FILE: lib2.kt
|
||||
@file:OptIn(FreezingIsDeprecated::class)
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
class Z(val x: Int)
|
||||
|
||||
val z1 = Z(42)
|
||||
|
||||
val z2 = Z(x.s.length)
|
||||
|
||||
// FILE: main.kt
|
||||
@file:OptIn(ObsoleteWorkersApi::class)
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
fun foo() {
|
||||
val worker = Worker.start()
|
||||
worker.execute(TransferMode.SAFE, { -> }, {
|
||||
it -> println(z1.x)
|
||||
}).consume { }
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo()
|
||||
println(z2.x)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
42
|
||||
3
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
class Z(val x: Int)
|
||||
|
||||
@ThreadLocal
|
||||
val z = Z(42)
|
||||
|
||||
// FILE: main.kt
|
||||
@file:OptIn(ObsoleteWorkersApi::class)
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
fun main() {
|
||||
println(z.x)
|
||||
val worker = Worker.start()
|
||||
worker.execute(TransferMode.SAFE, { -> }, {
|
||||
it -> println(z.x)
|
||||
}).consume { }
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
42
|
||||
42
|
||||
Reference in New Issue
Block a user