Add regression tests for obsolete issues

#KT-9304
 #KT-14961
 #KT-16549
 #KT-21080
 #KT-28234
 #KT-30102
 #KT-31994
 #KT-34291
 #KT-38099
 #KT-41174
 #KT-44622
 #KT-44701
 #KT-44781
 #KT-44849
 #KT-44978
 #KT-45081
 #KT-45286
 #KT-45383
 #KT-45444
 #KT-45907
This commit is contained in:
Alexander Udalov
2021-02-11 14:51:55 +01:00
parent 2666a93e6a
commit 21e9bd7ea2
41 changed files with 1150 additions and 0 deletions
@@ -0,0 +1,6 @@
fun Array<Array<Array<Array<Array<Array<Array<Array<Array<Array<Array<Array<Array<Array<Array<LongArray>>>>>>>>>>>>>>>.dimensions() = "OK"
fun box(): String =
arrayOf(arrayOf(arrayOf(arrayOf(arrayOf(arrayOf(arrayOf(arrayOf(arrayOf(arrayOf(arrayOf(arrayOf(arrayOf(arrayOf(arrayOf(
longArrayOf(42L)
))))))))))))))).dimensions()
@@ -0,0 +1,32 @@
// KT-45286
// MODULE: lib
// WITH_RUNTIME
// FILE: A.kt
package a
import kotlin.coroutines.*
var result = "Fail"
fun f() {
result = "OK"
}
fun g(block: suspend () -> Unit) {
block.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
inline fun h() = g(::f)
// MODULE: main(lib)
// FILE: B.kt
package b
fun box(): String {
a.h()
return a.result
}
@@ -0,0 +1,22 @@
// KT-44622
// MODULE: lib
// FILE: A.kt
package x
inline class A(val value: String)
fun interface B {
fun method(a: A): String
}
// MODULE: main(lib)
// FILE: B.kt
package y
import x.*
val b = B { it.value }
fun box(): String = b.method(A("OK"))
@@ -0,0 +1,22 @@
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
// KT-44849
import kotlin.coroutines.*
var result = "Fail"
class Wrapper(val action: suspend () -> Unit) {
init {
action.startCoroutine(Continuation(EmptyCoroutineContext) { it.getOrThrow() })
}
}
suspend fun some(a: String = "OK") {
result = a
}
fun box(): String {
Wrapper(::some)
return result
}
+27
View File
@@ -0,0 +1,27 @@
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
import kotlin.coroutines.*
import helpers.*
suspend fun suspendThere(v: A): A = suspendCoroutine { x ->
x.resume(v)
}
class A(var value: Int)
suspend operator fun A?.plus(a: A) = suspendThere(A((this?.value ?: 0) + a.value))
class B(var a: A)
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var b: B? = B(A(11))
builder { b?.a += A(31) }
if (b?.a?.value != 42) return "FAIL 0"
return "OK"
}
+25
View File
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
import kotlin.coroutines.*
object MyObject2 {
@JvmStatic
suspend fun enable(o: Any) {
if (o.hashCode() != 0) {
suspendCoroutine<Any> {}
}
}
}
fun go(block: suspend () -> Unit) {
block.startCoroutine(Continuation(EmptyCoroutineContext) { it.getOrThrow() })
}
fun box(): String {
go {
MyObject2.enable("")
}
return "OK"
}
+25
View File
@@ -0,0 +1,25 @@
// WITH_RUNTIME
import kotlin.coroutines.*
inline suspend fun foo(crossinline block: () -> String): String {
return bar { _ -> block() }
}
suspend fun bar(block: suspend (Int) -> String): String {
return block(1)
}
fun launch(block: suspend () -> String): String {
var result = ""
block.startCoroutine(Continuation(EmptyCoroutineContext) { result = it.getOrThrow() })
return result
}
fun box(): String {
return launch {
foo {
"OK"
}
}
}
@@ -0,0 +1,8 @@
// IGNORE_BACKEND: JVM
fun box(): String {
val a = BooleanWrap(false)
return if (a < true) "OK" else "Fail"
}
class BooleanWrap(private val value: Boolean): Comparable<Boolean> by value
@@ -0,0 +1,27 @@
// KT-16549
// IGNORE_BACKEND: JVM
class TailInline {
private inline fun act(action: () -> Unit) {
return action()
}
private var countDown = 10
tailrec fun test(): Int {
if (countDown < 5) return countDown
act {
countDown--
if (countDown < 1)
return countDown
else
return test() // GOTO countDown--
}
return countDown
}
}
fun box(): String {
val result = TailInline().test()
return if (result == 4) "OK" else "Fail: $result"
}
@@ -0,0 +1,18 @@
// KT-14961
// IGNORE_BACKEND: JVM, JS_IR, WASM
// WITH_RUNTIME
fun listOfFactor(number: Int): List<Int> {
tailrec fun listOfFactor(number: Int, acc: List<Int>): List<Int> {
(2..number).forEach {
if (number % it == 0) return listOfFactor(number / it, acc + it)
}
return acc
}
return listOfFactor(number, emptyList())
}
fun box(): String {
val factors = listOfFactor(60)
return if (factors.size == 4) "OK" else "Fail: $factors"
}
@@ -0,0 +1,16 @@
// IGNORE_BACKEND: JVM
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: SAM_CONVERSIONS
private fun interface Listener {
fun onChanged(): String
}
private class Foo {
private val listener = Listener { "OK" }
val result = listener.onChanged()
}
private val foo = Foo()
fun box(): String = foo.result
+15
View File
@@ -0,0 +1,15 @@
// IGNORE_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
fun box(): String =
testBug(null)
fun testBug(test: Test?): String =
test?.Inner()?.thing ?: "OK"
class Test(val name: String) {
inner class Inner {
val thing: String
get() = name
}
}
@@ -0,0 +1,7 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
inline class Location @JvmOverloads constructor(val value: String? = "OK")
fun box(): String = Location().value!!
+14
View File
@@ -0,0 +1,14 @@
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
inline class StringArray(val values: Array<String>)
fun foo(a1: StringArray, a2: StringArray): String {
var result = ""
for ((_, a) in arrayOf(a1, a2).withIndex()) {
result += a.values[0]
}
return result
}
fun box(): String = foo(StringArray(arrayOf("O")), StringArray(arrayOf("K")))
+10
View File
@@ -0,0 +1,10 @@
// IGNORE_BACKEND: JVM
fun box(): String {
var cur = 0
class Node(l: Int) {
val left = if (l > 0) Node(l - 1) else null
val ind: Int = (left?.ind ?: cur) + 1
}
return if (Node(5).ind == 6) "OK" else "Fail"
}
@@ -0,0 +1,10 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
fun box(): String = use {
class Local(val n: Int)
if (Local::class.java.declaringClass == null) "OK" else "Fail"
}
inline fun <T> use(block: () -> T): T = block()
+12
View File
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// IGNORE_BACKEND: WASM
// WASM_MUTE_REASON: STDLIB_TEXT
fun test(text: String): String {
when (text.takeWhile { it.isLetter() }) {
in arrayOf("a") -> return "OK"
}
return "FAIL"
}
fun box(): String = test("a")
@@ -0,0 +1,14 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FULL_JDK
// FILE: 1.kt
inline fun foo(crossinline init: (String) -> String): String =
listOf("OK").stream().map { init(it) }.findFirst().get()
inline fun bar(crossinline init: (String) -> String): String =
foo { foo(init) }
// FILE: 2.kt
fun box(): String = bar { it }
@@ -0,0 +1,16 @@
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_MULTI_MODULE_OLD_AGAINST_IR
// IGNORE_BACKEND_FIR: JVM_IR
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
inline fun foo(f: () -> Unit) {
f()
}
// FILE: 2.kt
fun box(): String = (bar@ l@ fun(): String {
foo { return@bar "OK" }
return "fail"
}) ()
+28
View File
@@ -0,0 +1,28 @@
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_MULTI_MODULE_OLD_AGAINST_IR
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
class M(size: Int) {
val m = IntArray(size) { 0 }
}
inline operator fun M.get(a: Any, b: Any, ifn: () -> Int) =
m[ifn()]
inline operator fun <reified T> M.set(a: T, b: Any, ifn: () -> Int, v: Int) {
if (b !is T) throw AssertionError()
m[ifn()] = v
}
// FILE: 2.kt
import test.*
fun box(): String {
val m = M(4)
m["a", "b", { 1 }] += 10
return if (m.m[1] == 10) "OK" else "Fail"
}