[K/N][Tests] Move codegen test sources cycles..innerClass

^KT-61259
This commit is contained in:
Vladimir Sukharev
2023-12-13 23:53:55 +01:00
committed by Space Team
parent 35d2be25b2
commit 71a834b778
282 changed files with 2376 additions and 756 deletions
@@ -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.inline.changingCapturedLocal
import kotlin.test.*
var log = ""
inline fun foo(x: Int, action: (Int) -> Unit) = action(x)
fun box(): String {
var x = 23
foo(x) {
log += "$it;"
x++
log += "$it;"
}
if (log != "23;23;") return "fail1: $log"
if (x != 24) return "fail2: $x"
return "OK"
}
@Test fun runTest() {
println(box())
}
@@ -0,0 +1 @@
OK
@@ -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.inline.classDeclarationInsideInline
import kotlin.test.*
fun f() {
run {
class Test1<T : Number, G>(val x: T, val y: G) {
override fun toString() = "test1: ${x.toDouble()}"
}
class Test2<X>(val a: Test1<Int, X>) {
override fun toString() = "test2"
}
val v = Test2(Test1(1, Test2(Test1(1, 3))))
println(v.a)
println(v.a.x)
println(v.a.y)
}
}
@Test fun test() {
f()
}
@@ -0,0 +1,3 @@
test1: 1.0
1
test2
@@ -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.inline.coercionToUnit
import kotlin.test.*
fun <T> myRun(action: () -> T): T = action()
fun foo(n: Number, b: Boolean) {
n.let {
if (b) return@let
myRun() { 42 }
}
}
@Test fun runTest() {
println(foo(42, false))
}
@@ -0,0 +1 @@
kotlin.Unit
@@ -0,0 +1,40 @@
/*
* 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.inline.correctOrderFunctionReference
import kotlin.test.*
class Foo(val a: String) {
fun test() = a
}
inline fun test(a: String, b: () -> String, c: () -> String, d: () -> String, e: String): String {
return a + b() + c() + d() + e
}
var effects = ""
fun create(a: String): Foo {
effects += a
return Foo(a)
}
fun create2(a: String, f: () -> String): Foo {
effects += a
return Foo(a)
}
fun box(): String {
val result = test(create("A").a, create("B")::a, create("C")::test, create2("E", create("D")::test)::test, create("F").a)
if (effects != "ABCDEF") return "fail 1: $effects"
return if (result == "ABCEF") "OK" else "fail 2: $result"
}
@Test fun runTest() {
println(box())
}
@@ -0,0 +1 @@
OK
@@ -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.inline.defaultArgs
import kotlin.test.*
class Z
inline fun Z.foo(x: Int = 42, y: Int = x) {
println(y)
}
@Test fun runTest() {
val z = Z()
z.foo()
}
@@ -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.
*/
package codegen.inline.genericFunctionReference
import kotlin.test.*
class Z<T>(val x: T)
inline fun<T, R> foo(x: T, f: (T) -> R): R {
return f(x)
}
@Test fun runTest() {
val arr = Array(1) { foo(it, ::Z) }
println(arr[0].x)
}
@@ -0,0 +1 @@
0
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.getClass
import kotlin.test.*
fun foo() {
val cls1: Any? = Int
val cls2: Any? = null
cls1?.let {
cls2?.let {
var itClass = it::class
}
}
}
@Test fun runTest() {
println("OK")
}
@@ -0,0 +1 @@
OK
+22
View File
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline0
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo(i1: Int, j1: Int): Int {
return i1 + j1
}
fun bar(i: Int, j: Int): Int {
return i + foo(i, j)
}
@Test fun runTest() {
println(bar(41, 2).toString())
}
@@ -0,0 +1 @@
84
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline1
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo(s4: String, s5: String): String {
return s4 + s5
}
fun bar(s1: String, s2: String, s3: String): String {
return s1 + foo(s2, s3)
}
@Test fun runTest() {
println(bar("Hello ", "wor", "ld"))
}
@@ -0,0 +1 @@
Hello world
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline10
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo(i2: Int, body: () -> Int): Int {
return i2 + body()
}
fun bar(i1: Int): Int {
return foo(i1) { 1 }
}
@Test fun runTest() {
println(bar(1).toString())
}
@@ -0,0 +1 @@
2
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline11
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun <reified T> foo (i2: Any): Boolean {
return i2 is T
}
fun bar(i1: Int): Boolean {
return foo<Double>(i1)
}
@Test fun runTest() {
println(bar(1).toString())
}
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline12
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun <T> foo (): Boolean {
return Any() is Any
}
fun bar(i1: Int): Boolean {
return foo<Double>()
}
@Test fun runTest() {
println(bar(1).toString())
}
+24
View File
@@ -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.inline.inline13
import kotlin.test.*
open class A<T1>()
class B<T2>() : A<T2>()
@Suppress("NOTHING_TO_INLINE")
inline fun <reified T: A<*>> foo(f: Any?): Boolean {
return f is T?
}
fun bar(): Boolean {
return foo<B<Int>>(B<Int>())
}
@Test fun runTest() {
println(bar().toString())
}
@@ -0,0 +1 @@
true
+31
View File
@@ -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.inline.inline14
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo3(i3: Int): Int {
return i3 + 3
}
@Suppress("NOTHING_TO_INLINE")
inline fun foo2(i2: Int): Int {
return i2 + 2
}
@Suppress("NOTHING_TO_INLINE")
inline fun foo1(i1: Int): Int {
return foo2(i1)
}
fun bar(i0: Int): Int {
return foo1(i0) + foo3(i0)
}
@Test fun runTest() {
println(bar(2).toString())
}
@@ -0,0 +1 @@
9
+26
View File
@@ -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.inline.inline15
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo2(i1: Int): Int {
return i1 + 1
}
@Suppress("NOTHING_TO_INLINE")
inline fun foo1(i1: Int, body: (Int) -> Int): Int {
return body(i1)
}
fun bar(i0: Int): Int {
return foo1(i0) { foo2(it) + 1 }
}
@Test fun runTest() {
println(bar(2).toString())
}
@@ -0,0 +1 @@
4
+26
View File
@@ -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.inline.inline16
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun <T, C : MutableCollection<in T>> foo(destination: C, predicate: (T) -> Boolean): C {
for (element in destination) {
val value = element as T
if (!predicate(value)) destination.add(value)
}
return destination
}
fun bar(): Boolean {
val result = foo <Int, MutableList<Int>> (mutableListOf(1, 2, 3)) { true }
return result.isEmpty()
}
@Test fun runTest() {
println(bar().toString())
}
@@ -0,0 +1 @@
false
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline17
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun <T> foo(i1: T, i2: T): List<T> {
val j1 = i1
val j2 = i2
return listOf(j1, j2)
}
fun bar(): List<Int> {
return foo <Int> (1, 2)
}
@Test fun runTest() {
println(bar().toString())
}
@@ -0,0 +1 @@
[1, 2]
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline18
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun <T> foo2(i2: T, j2: T, p2: (T, T) -> Boolean): Boolean {
return p2(i2, j2)
}
@Suppress("NOTHING_TO_INLINE")
inline fun <T> foo1(i1: T, j1: T, p1: (T, T) -> Boolean): Boolean {
return foo2<T>(i1, j1, p1)
}
fun bar(): Boolean {
val result = foo1 <Int> (3, 3) { x1: Int, x2: Int -> x1 == x2 }
return result
}
@Test fun runTest() {
println(bar().toString())
}
@@ -0,0 +1 @@
true
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline19
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline private fun foo(i: Int): Int {
val result = i
return result + i
}
fun bar(): Int {
return foo(1) + foo(2)
}
@Test fun runTest() {
println(bar().toString())
}
@@ -0,0 +1 @@
6
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline2
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo(i4: Int, i5: Int) {
println("hello $i4 $i5")
}
fun bar(i1: Int, i2: Int) {
foo(i1, i2)
}
@Test fun runTest() {
bar(1, 8)
}
@@ -0,0 +1 @@
hello 1 8
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline20
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun bar(block: () -> String) : String {
return block()
}
fun bar2() : String {
return bar { return "def" }
}
@Test fun runTest() {
println(bar2())
}
@@ -0,0 +1 @@
def
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline21
import kotlin.test.*
inline fun foo2(block2: () -> Int) : Int {
println("foo2")
return block2()
}
inline fun foo1(block1: () -> Int) : Int {
println("foo1")
return foo2(block1)
}
fun bar(block: () -> Int) : Int {
println("bar")
return foo1(block)
}
@Test fun runTest() {
println(bar { 33 })
}
@@ -0,0 +1,4 @@
bar
foo1
foo2
33
+24
View File
@@ -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.inline.inline22
import kotlin.test.*
inline fun foo2(i2: Int): Int {
return i2 + 3
}
inline fun foo1(i1: Int): Int {
return foo2(i1)
}
fun bar(): Int {
return foo1(11)
}
@Test fun runTest() {
println(bar().toString())
}
@@ -0,0 +1 @@
14
+20
View File
@@ -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.inline.inline23
import kotlin.test.*
inline fun <reified T> foo(i2: Any): T {
return i2 as T
}
fun bar(i1: Int): Int {
return foo<Int>(i1)
}
@Test fun runTest() {
println(bar(33))
}
@@ -0,0 +1 @@
33
+17
View File
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline24
import kotlin.test.*
fun foo() = println("foo")
fun bar() = println("bar")
inline fun baz(x: Unit = foo(), y: Unit) {}
@Test fun runTest() {
baz(y = bar())
}
@@ -0,0 +1,2 @@
bar
foo
+30
View File
@@ -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.inline.inline25
import kotlin.test.*
inline fun foo(block: String.() -> Unit) {
"Ok".block()
}
inline fun bar(block: (String) -> Unit) {
foo(block)
}
inline fun baz(block: String.() -> Unit) {
block("Ok")
}
@Test fun runTest() {
bar {
println(it)
}
baz {
println(this)
}
}
@@ -0,0 +1,2 @@
Ok
Ok
+18
View File
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline26
import kotlin.test.*
inline fun call(block1: () -> Unit, noinline block2: () -> Int): Int {
block1()
return block2()
}
@Test fun runTest() {
var x = 5
println(call({ x = 7 }, x::toInt))
}
@@ -0,0 +1 @@
5
+25
View File
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline3
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo(i4: Int, i5: Int): Int {
try {
return i4 / i5
} catch (e: Throwable) {
return i4
}
}
fun bar(i1: Int, i2: Int, i3: Int): Int {
return i1 + foo(i2, i3)
}
@Test fun runTest() {
println(bar(1, 8, 2).toString())
}
@@ -0,0 +1 @@
5
+22
View File
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline4
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo(i4: Int, i5: Int): Int {
if (i4 > 0) return i4
return i5
}
fun bar(i1: Int, i2: Int): Int {
return foo(i1, i2)
}
@Test fun runTest() {
println(bar(3, 8).toString())
}
@@ -0,0 +1 @@
3
+22
View File
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline5
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo(i2: Int, body: () -> Int): Int {
return i2 + body()
}
fun bar(i1: Int): Int {
return foo(i1) { return 33 }
}
@Test fun runTest() {
println(bar(1).toString())
}
@@ -0,0 +1 @@
33
+26
View File
@@ -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.inline.inline6
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo(body: () -> Unit) {
println("hello1")
body()
println("hello4")
}
fun bar() {
foo {
println("hello2")
println("hello3")
}
}
@Test fun runTest() {
bar()
}
@@ -0,0 +1,4 @@
hello1
hello2
hello3
hello4
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline7
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo(vararg args: Int) {
for (a in args) {
println(a.toString())
}
}
fun bar() {
foo(1, 2, 3)
}
@Test fun runTest() {
bar()
}
@@ -0,0 +1,3 @@
1
2
3
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.inline.inline8
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo(i3: Int, i4: Int) : Int {
return i3 + i3 + i4
}
fun bar(i1: Int, i2: Int) : Int {
return foo(i1 + i2, 2)
}
@Test fun runTest() {
println(bar(1, 2).toString())
}
@@ -0,0 +1 @@
8
+26
View File
@@ -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.inline.inline9
import kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun foo(i3: Int, i4: Int): Int {
return i3 + i3 + i4
}
fun quiz(i: Int) : Int {
println("hello")
return i + 1
}
fun bar(i1: Int, i2: Int): Int {
return foo(quiz(i1), i2)
}
@Test fun runTest() {
println(bar(1, 2).toString())
}
@@ -0,0 +1,2 @@
hello
6
@@ -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.inline.lambdaAsAny
import kotlin.test.*
inline fun foo(x: Any) {
println(if (x === x) "Ok" else "Fail")
}
@Test fun runTest() {
foo { 42 }
}
@@ -0,0 +1 @@
Ok
@@ -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.inline.lambdaInDefaultValue
import kotlin.test.*
inline fun inlineFun(param: String, lambda: (String) -> String = { it }): String {
return lambda(param)
}
fun box(): String {
return inlineFun("OK")
}
@Test fun runTest() {
println(box())
}
@@ -0,0 +1 @@
OK
@@ -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.inline.localFunctionInInitializerBlock
import kotlin.test.*
class Foo {
init {
bar()
}
}
inline fun bar() {
println({ "Ok" }())
}
@Test fun runTest() {
Foo()
}
@@ -0,0 +1 @@
Ok
@@ -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.inline.localObjectReturnedFromWhen
import kotlin.test.*
fun foo() {
123?.let {
object : () -> Unit {
override fun invoke() = Unit
}
}
}
@Test fun runTest() {
foo()
println("Ok")
}
@@ -0,0 +1 @@
Ok
@@ -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.inline.propertyAccessorInline
import kotlin.test.*
object C {
const val x = 42
}
fun getC(): C {
println(123)
return C
}
@Test fun runTest() {
println(getC().x)
}
@@ -0,0 +1,2 @@
123
42
@@ -0,0 +1,49 @@
package codegen.inline.redundantCoercionsCleaner
import kotlin.test.*
inline fun runAndThrow(action: () -> Unit): Nothing {
action()
throw Exception()
}
inline fun foo(): Int = runAndThrow {
return 1
}
@Test fun runTest() {
val result: Any = foo()
assertEquals(1, result)
}
// The test below is inspired by https://youtrack.jetbrains.com/issue/KT-48876.
fun bar2(): Any {
return foo2()
}
inline fun foo2(): Int {
return try {
throw Throwable()
} catch (e: Throwable) {
return 2
}
}
@Test fun runTest2() {
assertEquals(2, bar2())
}
// Test for https://youtrack.jetbrains.com/issue/KT-49356.
inline fun foo3(): Int {
return (return 3)
}
fun bar3(): Any {
return foo3()
}
@Test fun runTest3() {
assertEquals(3, bar3())
}
@@ -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.inline.returnLocalClassFromBlock
import kotlin.test.*
inline fun <R> call(block: ()->R): R {
try {
return block()
} finally {
println("Zzz")
}
}
@Test fun runTest() {
call { class Z(); Z() }
}
@@ -0,0 +1 @@
Zzz
@@ -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.inline.statementAsLastExprInBlock
import kotlin.test.*
fun foo() {
val cls1: Any? = Int
val cls2: Any? = null
cls1?.let {
if (cls2 != null) {
val zzz = 42
}
}
}
@Test fun runTest() {
println("OK")
}
@@ -0,0 +1 @@
OK
@@ -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.inline.twiceInlinedObject
import kotlin.test.*
inline fun exec(f: () -> Unit) = f()
inline fun test2() {
val obj = object {
fun sayOk() = println("Ok")
}
obj.sayOk()
}
inline fun noExec(f: () -> Unit) { }
@Test fun runTest() {
exec {
test2()
}
noExec {
test2()
}
}
@@ -0,0 +1 @@
Ok
@@ -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.inline.typeSubstitutionInFakeOverride
import kotlin.test.*
abstract class A {
inline fun <reified T : Any> baz(): String {
return T::class.simpleName!!
}
}
class B : A() {
fun bar(): String {
return baz<OK>()
}
}
class OK
@Test fun runTest() {
println(B().bar())
}
@@ -0,0 +1 @@
OK