Skip to content

Commit 9ac91e4

Browse files
homurollSpace Team
authored and
Space Team
committed
[K/N][tests] Couple of reproducers for #KT-67218
1 parent 1a630b5 commit 9ac91e4

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

kotlin-native/backend.native/tests/build.gradle

+14
Original file line numberDiff line numberDiff line change
@@ -2814,6 +2814,20 @@ standaloneTest("devirtualization_anonymousObject") {
28142814
source = "codegen/devirtualization/anonymousObject.kt"
28152815
}
28162816

2817+
standaloneTest("devirtualization_kt67281c") {
2818+
disabled = (cacheTesting != null) // Cache is not compatible with -opt.
2819+
useGoldenData = true
2820+
flags = ["-opt"]
2821+
source = "codegen/devirtualization/kt67218c.kt"
2822+
}
2823+
2824+
standaloneTest("devirtualization_kt67281i") {
2825+
disabled = (cacheTesting != null) // Cache is not compatible with -opt.
2826+
useGoldenData = true
2827+
flags = ["-opt"]
2828+
source = "codegen/devirtualization/kt67218i.kt"
2829+
}
2830+
28172831
tasks.register("interfaceCallsNCasts_conservativeItable", KonanLocalTest) {
28182832
useGoldenData = true
28192833
source = "codegen/interfaceCallsNCasts/conservativeItable.kt"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
open class A {
7+
open fun foo() = 42
8+
}
9+
10+
open class B : A() {
11+
override fun foo() = 117
12+
}
13+
14+
class C : A()
15+
16+
class D : A()
17+
18+
class E : B()
19+
20+
class F : B()
21+
22+
class G : B()
23+
24+
fun foo(a: A) = a.foo()
25+
26+
fun box(): String {
27+
if (foo(E()) != 117) return "fail 1"
28+
if (foo(F()) != 117) return "fail 2"
29+
if (foo(G()) != 117) return "fail 3"
30+
if (foo(C()) != 42) return "fail 4"
31+
if (foo(D()) != 42) return "fail 5"
32+
33+
return "OK"
34+
}
35+
36+
fun main() = println(box())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OK
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
interface I {
7+
fun foo() = 42
8+
}
9+
10+
open class B : I {
11+
override fun foo() = 117
12+
}
13+
14+
class C : I
15+
16+
class D : I
17+
18+
class E : B()
19+
20+
class F : B()
21+
22+
class G : B()
23+
24+
fun foo(i: I) = i.foo()
25+
26+
fun box(): String {
27+
if (foo(E()) != 117) return "fail 1"
28+
if (foo(F()) != 117) return "fail 2"
29+
if (foo(G()) != 117) return "fail 3"
30+
if (foo(C()) != 42) return "fail 4"
31+
if (foo(D()) != 42) return "fail 5"
32+
33+
return "OK"
34+
}
35+
36+
fun main() = println(box())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OK

0 commit comments

Comments
 (0)