Add tests for obsolete issues

(Test for KT-37331 is added to multiplatform/defaultArguments/suspend.kt.)

 #KT-30080
 #KT-33641
 #KT-36237
 #KT-36952
 #KT-37331
 #KT-38920
 #KT-39256
 #KT-42415
 #KT-44636
 #KT-45704
 #KT-47084
 #KT-47894
This commit is contained in:
Alexander Udalov
2022-03-02 00:34:21 +01:00
parent f0290d8c98
commit 328853dffe
20 changed files with 662 additions and 2 deletions
@@ -0,0 +1,9 @@
// IGNORE_BACKEND: JVM
inline fun g(h: () -> String): String = h()
fun box(): String {
val result = "OK"
fun Any.f(): String = result
return g("Fail"::f)
}
@@ -0,0 +1,23 @@
interface Kla6 {
fun fu32()
}
class Kla7 {
inline fun fu33(crossinline f: (Int) -> Any) =
object : Kla6 {
override fun fu32() {
f(1)
}
var ttmh: Int = throw RuntimeException()
}.fu32()
inline fun fu34(crossinline f: (Int) -> Any) =
fu33 { f(1) }
}
fun box(): String = try {
Kla7().fu34 {}
"Fail"
} catch (e: RuntimeException) {
"OK"
}
@@ -0,0 +1,17 @@
inline fun inlineCall(block: (CharSequence, CharSequence) -> Unit) {
for (i in 0..0) {
val s = "K".takeIf { true }
block(
"O",
s ?: continue
)
}
}
fun box(): String {
inlineCall { a, b ->
return a.toString() + b
}
return "Fail"
}
@@ -0,0 +1,30 @@
// IGNORE_BACKEND: JVM
// WITH_STDLIB
// WITH_COROUTINES
// DONT_RUN_GENERATED_CODE: JS
import helpers.*
import kotlin.coroutines.*
var iterations = 0
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = ""
tailrec suspend fun theLoop(value: Int, string: String) {
if (value == 2) return
result += string
if (++iterations > 2) error("Fail: too many iterations")
theLoop(value + 1, "b")
}
builder {
theLoop(0, "a")
}
return if (result == "ab") "OK" else "Fail $result"
}
@@ -0,0 +1,29 @@
// IGNORE_BACKEND: JVM, JS, JS_IR
// KT-30080
data class A(
val z: BooleanArray,
var c: CharArray,
val b: ByteArray,
val s: ShortArray,
val i: IntArray,
val f: FloatArray,
val j: LongArray,
val d: DoubleArray,
)
fun box(): String {
val a = A(
booleanArrayOf(true),
charArrayOf('a'),
byteArrayOf(1),
shortArrayOf(2),
intArrayOf(3),
floatArrayOf(4f),
longArrayOf(5),
doubleArrayOf(6.0),
)
return if (a.toString() == "A(z=[true], c=[a], b=[1], s=[2], i=[3], f=[4.0], j=[5], d=[6.0])")
"OK"
else "Fail: $a"
}
@@ -0,0 +1,9 @@
fun f(block: () -> Unit): String {
block()
return "OK"
}
tailrec fun foo(a: String = run { f {} }): String =
if (a.length == 0) foo() else a
fun box(): String = foo()
@@ -20,7 +20,8 @@ actual interface I {
}
class II : I {
override suspend fun f(p: Int): String = "OK"
override suspend fun f(p: Int): String =
if (p == 1) "OK" else "Fail: $p"
}
fun builder(c: suspend () -> Unit) {
@@ -33,4 +34,4 @@ fun box(): String {
res = II().f()
}
return res
}
}
@@ -0,0 +1,6 @@
// IGNORE_BACKEND: WASM
fun box(): String {
fun a(a: Any) = a === 1.1 is Double
return if (a(true)) "OK" else "Fail"
}
@@ -0,0 +1,7 @@
// TARGET_BACKEND: JVM
// WITH_STDLIB
fun box(): String {
val a = 1.javaClass
return if (a == 2L.javaClass) "Fail" else "OK"
}
+10
View File
@@ -0,0 +1,10 @@
inline fun <reified P> cast(value: Any): P =
cast0<Int, P>(value)
inline fun <reified P, reified Z> cast0(
value: Any,
func: (Any) -> Z = { it as Z }
): Z = func(value)
fun box(): String =
cast<String>("OK")
@@ -0,0 +1,13 @@
interface I
class C<T>
private inline fun <reified T> C<T>.f() = object : I {
val unused = T::class
}
fun box(): String {
val t1 = C<String>().f()
val t2 = C<String>().f()
arrayOf(t1, t2)
return "OK"
}
@@ -0,0 +1,23 @@
// WITH_STDLIB
fun box(): String {
val x = Result.success(42)
var y = 0
when (x) {
Result.success(42) -> {
y++
}
else -> {
y -= 10
}
}
when (val z = Result.success(42)) {
Result.success(42) -> {
y++
}
else -> {
y -= 100
}
}
return if (y == 2) "OK" else "Fail $y"
}