[Tests] Migrate backend-independent tests from native to compiler/testData.

^KT-65979
This commit is contained in:
Vladimir Sukharev
2024-02-25 18:25:58 +01:00
committed by Space Team
parent dd9332d9e1
commit febac0dd5f
640 changed files with 68168 additions and 6313 deletions
@@ -1,24 +0,0 @@
/*
* 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 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"
}
@@ -1,24 +0,0 @@
/*
* 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 kotlin.test.*
fun box(): String {
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))))
assertEquals("test1: 1.0", v.a.toString())
assertEquals("1", v.a.x.toString())
assertEquals("test2", v.a.y.toString())
}
return "OK"
}
@@ -1,21 +0,0 @@
/*
* 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 kotlin.test.*
fun <T> myRun(action: () -> T): T = action()
fun foo(n: Number, b: Boolean) {
n.let {
if (b) return@let
myRun() { 42 }
}
}
fun box(): String {
assertEquals(Unit, foo(42, false))
return "OK"
}
@@ -1,34 +0,0 @@
/*
* 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.
*/
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"
}
@@ -1,21 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
class Z
inline fun Z.foo(x: Int = 42, y: Int = x) {
sb.appendLine(y)
}
fun box(): String {
val z = Z()
z.foo()
assertEquals("42\n", sb.toString())
return "OK"
}
@@ -1,18 +0,0 @@
// MODULE: lib
// FILE: lib.kt
package a
inline fun foo(x: Int, y: Int = 117) = x + y
// MODULE: main(lib)
// FILE: main.kt
import a.*
import kotlin.test.*
fun box(): String {
assertEquals(122, foo(5))
assertEquals(47, foo(5, 42))
return "OK"
}
@@ -1,18 +0,0 @@
/*
* 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 kotlin.test.*
class Z<T>(val x: T)
inline fun<T, R> foo(x: T, f: (T) -> R): R {
return f(x)
}
fun box(): String {
val arr = Array(1) { foo(it, ::Z) }
assertEquals(0, arr[0].x)
return "OK"
}
-22
View File
@@ -1,22 +0,0 @@
/*
* 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 kotlin.test.*
fun foo() {
val cls1: Any? = Int
val cls2: Any? = null
cls1?.let {
cls2?.let {
var itClass = it::class
}
}
}
fun box(): String {
foo()
return "OK"
}
-21
View File
@@ -1,21 +0,0 @@
/*
* 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 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)
}
fun box(): String {
assertEquals(84, bar(41, 2))
return "OK"
}
-22
View File
@@ -1,22 +0,0 @@
/*
* 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 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)
}
fun box(): String {
assertEquals("Hello world", bar("Hello ", "wor", "ld"))
return "OK"
}
-20
View File
@@ -1,20 +0,0 @@
/*
* 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 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 }
}
fun box(): String {
assertEquals(2, bar(1))
return "OK"
}
-20
View File
@@ -1,20 +0,0 @@
/*
* 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 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)
}
fun box(): String {
assertFalse(bar(1))
return "OK"
}
-20
View File
@@ -1,20 +0,0 @@
/*
* 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 kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun <T> foo (): Boolean {
return Any() is Any
}
fun bar(i1: Int): Boolean {
return foo<Double>()
}
fun box(): String {
assertTrue(bar(1))
return "OK"
}
-23
View File
@@ -1,23 +0,0 @@
/*
* 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 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>())
}
fun box(): String {
assertTrue(bar())
return "OK"
}
-30
View File
@@ -1,30 +0,0 @@
/*
* 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 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)
}
fun box(): String {
assertEquals(9, bar(2))
return "OK"
}
-25
View File
@@ -1,25 +0,0 @@
/*
* 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 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 }
}
fun box(): String {
assertEquals(4, bar(2))
return "OK"
}
-25
View File
@@ -1,25 +0,0 @@
/*
* 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 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()
}
fun box(): String {
assertFalse(bar())
return "OK"
}
-22
View File
@@ -1,22 +0,0 @@
/*
* 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 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)
}
fun box(): String {
assertEquals("[1, 2]", bar().toString())
return "OK"
}
-22
View File
@@ -1,22 +0,0 @@
/*
* 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 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)
}
fun box(): String {
assertEquals(6, bar())
return "OK"
}
-24
View File
@@ -1,24 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
@Suppress("NOTHING_TO_INLINE")
inline fun foo(i4: Int, i5: Int) {
sb.appendLine("hello $i4 $i5")
}
fun bar(i1: Int, i2: Int) {
foo(i1, i2)
}
fun box(): String {
bar(1, 8)
assertEquals("hello 1 8\n", sb.toString())
return "OK"
}
-19
View File
@@ -1,19 +0,0 @@
/*
* 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 kotlin.test.*
@Suppress("NOTHING_TO_INLINE")
inline fun bar(block: () -> String) : String {
return block()
}
fun bar2() : String {
return bar { return "OK" }
}
fun box(): String {
return bar2()
}
-36
View File
@@ -1,36 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
inline fun foo2(block2: () -> Int) : Int {
sb.appendLine("foo2")
return block2()
}
inline fun foo1(block1: () -> Int) : Int {
sb.appendLine("foo1")
return foo2(block1)
}
fun bar(block: () -> Int) : Int {
sb.appendLine("bar")
return foo1(block)
}
fun box(): String {
sb.appendLine(bar { 33 })
assertEquals("""
bar
foo1
foo2
33
""".trimIndent(), sb.toString())
return "OK"
}
-23
View File
@@ -1,23 +0,0 @@
/*
* 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 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)
}
fun box(): String {
assertEquals(14, bar())
return "OK"
}
-19
View File
@@ -1,19 +0,0 @@
/*
* 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 kotlin.test.*
inline fun <reified T> foo(i2: Any): T {
return i2 as T
}
fun bar(i1: Int): Int {
return foo<Int>(i1)
}
fun box(): String {
assertEquals(33, bar(33))
return "OK"
}
-27
View File
@@ -1,27 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
fun myPrintln(s: String): Unit {
sb.appendLine(s)
}
fun foo() = myPrintln("foo")
fun bar() = myPrintln("bar")
inline fun baz(x: Unit = foo(), y: Unit) {}
fun box(): String {
baz(y = bar())
assertEquals("""
bar
foo
""".trimIndent(), sb.toString())
return "OK"
}
-30
View File
@@ -1,30 +0,0 @@
/*
* 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 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")
}
fun box(): String {
bar {
assertEquals("Ok", it)
}
baz {
assertEquals("Ok", this)
}
return "OK"
}
-18
View File
@@ -1,18 +0,0 @@
/*
* 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 kotlin.test.*
inline fun call(block1: () -> Unit, noinline block2: () -> Int): Int {
block1()
return block2()
}
fun box(): String {
var x = 5
assertEquals(5, call({ x = 7 }, x::toInt))
return "OK"
}
-24
View File
@@ -1,24 +0,0 @@
/*
* 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 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)
}
fun box(): String {
assertEquals(5, bar(1, 8, 2))
return "OK"
}
-21
View File
@@ -1,21 +0,0 @@
/*
* 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 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)
}
fun box(): String {
assertEquals(3, bar(3, 8))
return "OK"
}
-21
View File
@@ -1,21 +0,0 @@
/*
* 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 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 }
}
fun box(): String {
assertEquals(33, bar(1))
return "OK"
}
-35
View File
@@ -1,35 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
@Suppress("NOTHING_TO_INLINE")
inline fun foo(body: () -> Unit) {
sb.appendLine("hello1")
body()
sb.appendLine("hello4")
}
fun bar() {
foo {
sb.appendLine("hello2")
sb.appendLine("hello3")
}
}
fun box(): String {
bar()
assertEquals("""
hello1
hello2
hello3
hello4
""".trimIndent(), sb.toString())
return "OK"
}
-31
View File
@@ -1,31 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
@Suppress("NOTHING_TO_INLINE")
inline fun foo(vararg args: Int) {
for (a in args) {
sb.appendLine(a.toString())
}
}
fun bar() {
foo(1, 2, 3)
}
fun box(): String {
bar()
assertEquals("""
1
2
3
""".trimIndent(), sb.toString())
return "OK"
}
-20
View File
@@ -1,20 +0,0 @@
/*
* 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 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)
}
fun box(): String {
assertEquals(8, bar(1, 2))
return "OK"
}
-33
View File
@@ -1,33 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
@Suppress("NOTHING_TO_INLINE")
inline fun foo(i3: Int, i4: Int): Int {
return i3 + i3 + i4
}
fun quiz(i: Int) : Int {
sb.appendLine("hello")
return i + 1
}
fun bar(i1: Int, i2: Int): Int {
return foo(quiz(i1), i2)
}
fun box(): String {
sb.appendLine(bar(1, 2).toString())
assertEquals("""
hello
6
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,22 +0,0 @@
// MODULE: lib
// FILE: lib.kt
package a
fun foo(n: Int, block: (Int) -> Int): Int {
val arr = IntArray(n) { block(it) }
var sum = 0
for (x in arr) sum += x
return sum
}
// MODULE: main(lib)
// FILE: main.kt
import a.*
import kotlin.test.*
fun box(): String {
assertEquals(42, foo(7) { it * 2 })
return "OK"
}
@@ -1,19 +0,0 @@
// MODULE: lib
// FILE: lib.kt
package a
class E(val x: String) {
inner class Inner {
inline fun foo(y: String) = x + y
}
}
// MODULE: main(lib)
// FILE: main.kt
import a.*
fun box(): String {
return E("O").Inner().foo("K")
}
@@ -1,18 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
inline fun foo(x: Any) {
sb.append(if (x === x) "OK" else "FAIL")
}
fun box(): String {
foo { 42 }
return sb.toString()
}
@@ -1,14 +0,0 @@
/*
* 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 kotlin.test.*
inline fun inlineFun(param: String, lambda: (String) -> String = { it }): String {
return lambda(param)
}
fun box(): String {
return inlineFun("OK")
}
@@ -1,35 +0,0 @@
// KT-64511: lateinit is not lowered with caches
// DISABLE_NATIVE: cacheMode=STATIC_EVERYWHERE
// DISABLE_NATIVE: cacheMode=STATIC_PER_FILE_EVERYWHERE
// MODULE: lib
// FILE: lib.kt
package a
fun IntArray.forEachNoInline(block: (Int) -> Unit) = this.forEach { block(it) }
inline fun foo(values: IntArray, crossinline block: (Int, Int, Int) -> Int): Int {
val o = object {
lateinit var s: String
var x: Int = 42
}
values.forEachNoInline {
o.x = block(o.x, o.s.length, it)
}
return o.x
}
// MODULE: main(lib)
// FILE: main.kt
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
import a.*
import kotlin.test.*
fun box(): String {
assertFailsWith<UninitializedPropertyAccessException> {
foo(intArrayOf(1, 2, 3)) { x, y, z -> x + y - z }
}
return "OK"
}
@@ -1,23 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
class Foo {
init {
bar()
}
}
inline fun bar() {
sb.append({ "OK" }())
}
fun box(): String {
Foo()
return sb.toString()
}
@@ -1,19 +0,0 @@
/*
* 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 kotlin.test.*
fun foo() {
123?.let {
object : () -> Unit {
override fun invoke() = Unit
}
}
}
fun box(): String {
foo()
return "OK"
}
@@ -1,29 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
object C {
const val x = 42
}
fun getC(): C {
sb.appendLine(123)
return C
}
fun box(): String {
sb.appendLine(getC().x)
assertEquals("""
123
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,17 +0,0 @@
import kotlin.test.*
inline fun runAndThrow(action: () -> Unit): Nothing {
action()
throw Exception()
}
inline fun foo(): Int = runAndThrow {
return 1
}
fun box(): String {
val result: Any = foo()
assertEquals(1, result)
return "OK"
}
@@ -1,20 +0,0 @@
import kotlin.test.*
// 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
}
}
fun box(): String {
assertEquals(2, bar2())
return "OK"
}
@@ -1,16 +0,0 @@
import kotlin.test.*
// Test for https://youtrack.jetbrains.com/issue/KT-49356.
inline fun foo3(): Int {
return (return 3)
}
fun bar3(): Any {
return foo3()
}
fun box(): String {
assertEquals(3, bar3())
return "OK"
}
@@ -1,21 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
inline fun <R> call(block: ()->R): R {
try {
return block()
} finally {
sb.append("OK")
}
}
fun box(): String {
call { class Z(); Z() }
return sb.toString()
}
@@ -1,25 +0,0 @@
// MODULE: lib
// FILE: lib.kt
package a
fun IntArray.forEachNoInline(block: (Int) -> Unit) = this.forEach { block(it) }
inline fun fold(initial: Int, values: IntArray, crossinline block: (Int, Int) -> Int): Int {
var res = initial
values.forEachNoInline {
res = block(res, it)
}
return res
}
// MODULE: main(lib)
// FILE: main.kt
import a.*
import kotlin.test.*
fun box(): String {
assertEquals(6, fold(0, intArrayOf(1, 2, 3)) { x, y -> x + y })
return "OK"
}
@@ -1,22 +0,0 @@
/*
* 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 kotlin.test.*
fun foo() {
val cls1: Any? = Int
val cls2: Any? = null
cls1?.let {
if (cls2 != null) {
val zzz = 42
}
}
}
fun box(): String {
foo()
return "OK"
}
@@ -1,30 +0,0 @@
/*
* 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 kotlin.test.*
val sb = StringBuilder()
inline fun exec(f: () -> Unit) = f()
inline fun test2() {
val obj = object {
fun sayOk() = sb.append("OK")
}
obj.sayOk()
}
inline fun noExec(f: () -> Unit) { }
fun box(): String {
exec {
test2()
}
noExec {
test2()
}
return sb.toString()
}
@@ -1,24 +0,0 @@
/*
* 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 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
fun box(): String {
return B().bar()
}