Skip to content

Commit 6207b67

Browse files
committed
Add tests for KT-77008, KT-78127, KT-74588 and KT-80208
1 parent ddf2e89 commit 6207b67

File tree

27 files changed

+1154
-0
lines changed

27 files changed

+1154
-0
lines changed

analysis/low-level-api-fir/tests-gen/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLBlackBoxTestGenerated.java

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analysis/low-level-api-fir/tests-gen/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLReversedBlackBoxTestGenerated.java

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// IGNORE_BACKEND_K2: ANY
2+
// ISSUE: KT-78127
3+
4+
fun <T : Any> materialize(): T {
5+
return "OK" as T
6+
}
7+
8+
var b = true
9+
10+
fun foo(x: String): String = x
11+
fun foo(x: Int): Int = x
12+
13+
fun box(): String {
14+
var x: String? = null
15+
16+
x = if (b) materialize() else throw Exception()
17+
18+
return foo(x)
19+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// IGNORE_BACKEND_K2: ANY
2+
// TARGET_BACKEND: JVM
3+
// ISSUE: KT-74588
4+
5+
// FILE: JavaUtils.java
6+
public class JavaUtils {
7+
// Nullable
8+
public static <T extends String> T findViewById(int id) {
9+
return null;
10+
}
11+
12+
}
13+
14+
// FILE: main.kt
15+
var view: String? = null
16+
17+
// checkNotNull
18+
fun foo(t: String?) {
19+
view = if (t != null) {
20+
t
21+
} else {
22+
JavaUtils.findViewById(1000)
23+
}
24+
}
25+
26+
fun box(): String {
27+
foo(null)
28+
if (view != null) return "fail 1"
29+
foo("OK")
30+
return view!!
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// IGNORE_BACKEND_K2: ANY
2+
// ISSUE: KT-77008
3+
4+
interface I {
5+
fun func(): String
6+
}
7+
8+
class A : I {
9+
override fun func(): String = "OK"
10+
}
11+
12+
class B : I {
13+
override fun func(): String ="Fail B"
14+
}
15+
16+
fun <T> materialize(): T {
17+
return A() as T
18+
}
19+
20+
class MyThrowable : Throwable("")
21+
22+
fun box(): String {
23+
val i: I
24+
// K1: OK
25+
// K2: Fails in Runtime with "class A cannot be cast to class B"
26+
i = try {
27+
materialize()
28+
} catch(e: MyThrowable) {
29+
B()
30+
}
31+
return i.func()
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// IGNORE_BACKEND_K1: ANY
2+
// IGNORE_BACKEND_K2: ANY
3+
// ISSUE: KT-77008
4+
5+
interface I
6+
7+
interface I2 : I {
8+
fun func(): String
9+
}
10+
11+
class A : I2 {
12+
override fun func(): String = "OK"
13+
}
14+
15+
class B : I2 {
16+
override fun func(): String ="Fail B"
17+
}
18+
19+
fun <T : I2> materialize(): T {
20+
return A() as T
21+
}
22+
23+
class MyThrowable : Throwable("")
24+
25+
fun box(): String {
26+
val i: I
27+
i = try {
28+
materialize()
29+
} catch(e: MyThrowable) {
30+
B()
31+
}
32+
return i.func()
33+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// IGNORE_BACKEND_K2: ANY
2+
// ISSUE: KT-80208
3+
4+
class A(val s: String)
5+
6+
var result: A? = null
7+
8+
fun test(json: String) {
9+
result = try {
10+
build(json) {
11+
A(json)
12+
}
13+
} catch (e: Exception) {
14+
return
15+
}
16+
}
17+
18+
fun <T> build(str: String, builder: (String) -> T): T {
19+
return builder.invoke(str)
20+
}
21+
22+
fun box(): String {
23+
test("OK")
24+
25+
return result!!.s
26+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// IGNORE_BACKEND_K2: ANY
2+
// ISSUE: KT-77008
3+
4+
interface I {
5+
fun func(): String
6+
}
7+
8+
class A : I {
9+
override fun func(): String = "OK"
10+
}
11+
12+
class B : I {
13+
override fun func(): String ="Fail B"
14+
}
15+
16+
fun <T> materialize(): T {
17+
return A() as T
18+
}
19+
20+
var b = true
21+
22+
fun box(): String {
23+
val i: I
24+
// K1: OK
25+
// K2: Fails in Runtime with "class A cannot be cast to class B"
26+
i = when (b) {
27+
true -> materialize()
28+
else -> B()
29+
}
30+
return i.func()
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// IGNORE_BACKEND_K1: ANY
2+
// IGNORE_BACKEND_K2: ANY
3+
// ISSUE: KT-77008
4+
5+
interface I
6+
7+
interface I2 : I {
8+
fun func(): String
9+
}
10+
11+
class A : I2 {
12+
override fun func(): String = "OK"
13+
}
14+
15+
class B : I2 {
16+
override fun func(): String ="Fail B"
17+
}
18+
19+
fun <T : I2> materialize(): T {
20+
return A() as T
21+
}
22+
23+
var b = true
24+
25+
fun box(): String {
26+
val i: I
27+
i = when (b) {
28+
true -> materialize()
29+
else -> B()
30+
}
31+
return i.func()
32+
}

0 commit comments

Comments
 (0)