Skip to content

Commit 58be478

Browse files
francescoo22Space Team
authored andcommitted
[Tests] Add tests for type parameters captured by synthetic accessors
^KT-79739
1 parent bdac858 commit 58be478

File tree

6 files changed

+179
-0
lines changed

6 files changed

+179
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* MODULE name=<main> */
2+
3+
/* FILE package=<root> fileName=leakingCapturedTypeParameter.kt */
4+
5+
public open class A<T : Any?>
6+
/* TARGET declaration */ private fun foo(x: T): T
7+
internal inline fun callFoo(x: T): T
8+
/* ACCESSOR use-site */ access$foo<T>($this = <this>, x = x)
9+
/* TARGET declaration */ private fun <U : Any?> baz(x: T, y: U): Pair<T, U>
10+
internal inline fun <U : Any?> callBaz(x: T, y: U): Pair<T, U>
11+
/* ACCESSOR use-site */ access$baz<T, U>($this = <this>, x = x, y = y)
12+
public inner class B<S : Any?>
13+
/* TARGET declaration */ private fun barB(x: T, y: S): Pair<T, S>
14+
internal inline fun callBarB(x: T, y: S): Pair<T, S>
15+
/* ACCESSOR use-site */ access$barB<S, T>($this = <this>, x = x, y = y)
16+
/* ACCESSOR declaration */ internal /* static */ fun <S : Any?, T : Any?> access$barB($this: B<S, T>, x: T, y: S): Pair<T, S>
17+
/* TARGET use-site */ $this.barB(x = x, y = y)
18+
public inner class C<S : Any?>
19+
/* TARGET declaration */ private constructor(x: S) /* primary */
20+
internal inline fun copy(): C<Int, T>
21+
/* ACCESSOR use-site */ access$<outer-this-0><S, T>($this = <this>)
22+
/* ACCESSOR use-site */ access$<outer-this-0><S, T>($this = <this>).C<Int>(x = 42, $constructor_marker = null)
23+
/* ACCESSOR declaration */ private fun <outer-this-0>(): A<T>
24+
/* TARGET use-site */ <this>
25+
/* ACCESSOR declaration */ internal constructor(x: S, $constructor_marker: SyntheticConstructorMarker?)
26+
/* TARGET use-site */ <this>.C<S>(x = x)
27+
/* ACCESSOR declaration */ internal /* static */ fun <S : Any?, T : Any?> access$<outer-this-0>($this: C<S, T>): A<T>
28+
/* ACCESSOR use-site */ $this.<outer-this-0>()
29+
public companion object Companion
30+
/* TARGET declaration */ private fun barCompanion(x: Any): Any
31+
internal inline fun callBarCompanion(x: Any): Any
32+
/* ACCESSOR use-site */ access$barCompanion($this = <this>, x = x)
33+
/* ACCESSOR declaration */ internal /* static */ fun access$barCompanion($this: Companion, x: Any): Any
34+
/* TARGET use-site */ $this.barCompanion(x = x)
35+
public class Nested
36+
/* TARGET declaration */ private fun barNested(x: Any): Any
37+
internal inline fun callBarNested(x: Any): Any
38+
/* ACCESSOR use-site */ access$barNested($this = <this>, x = x)
39+
/* ACCESSOR declaration */ internal /* static */ fun access$barNested($this: Nested, x: Any): Any
40+
/* TARGET use-site */ $this.barNested(x = x)
41+
public inner class D : A<Int>
42+
/* TARGET declaration */ private fun barD(x: T): T
43+
internal inline fun callBarD(x: T): T
44+
/* ACCESSOR use-site */ access$barD<T>($this = <this>, x = x)
45+
/* ACCESSOR declaration */ internal /* static */ fun <T : Any?> access$barD($this: D<T>, x: T): T
46+
/* TARGET use-site */ $this.barD(x = x)
47+
/* TARGET declaration */ private fun listHead(xs: List<T>): T
48+
internal inline fun callListHead(xs: List<T>): T
49+
/* ACCESSOR use-site */ access$listHead<T>($this = <this>, xs = xs)
50+
internal inline fun <reified R : Any?> callFooReified(x: T): R?
51+
/* ACCESSOR use-site */ access$foo<T>($this = <this>, x = x)
52+
/* ACCESSOR declaration */ internal /* static */ fun <T : Any?> access$foo($this: A<T>, x: T): T
53+
/* TARGET use-site */ $this.foo(x = x)
54+
/* ACCESSOR declaration */ internal /* static */ fun <T : Any?, U : Any?> access$baz($this: A<T>, x: T, y: U): Pair<T, U>
55+
/* TARGET use-site */ $this.baz<U>(x = x, y = y)
56+
/* ACCESSOR declaration */ internal /* static */ fun <T : Any?> access$listHead($this: A<T>, xs: List<T>): T
57+
/* TARGET use-site */ $this.listHead(xs = xs)
58+
/* TARGET declaration */ <this>: A<T>
59+
public class E : A<Int>
60+
/* TARGET declaration */ private fun barE(x: Int): Int
61+
internal inline fun callBarE(x: Int): Int
62+
/* ACCESSOR use-site */ access$barE($this = <this>, x = x)
63+
public inner class F
64+
/* TARGET declaration */ private fun barF(x: Int): Int
65+
internal inline fun callBarF(x: Int): Int
66+
/* ACCESSOR use-site */ access$barF($this = <this>, x = x)
67+
/* ACCESSOR declaration */ internal /* static */ fun access$barF($this: F, x: Int): Int
68+
/* TARGET use-site */ $this.barF(x = x)
69+
/* ACCESSOR declaration */ internal /* static */ fun access$barE($this: E, x: Int): Int
70+
/* TARGET use-site */ $this.barE(x = x)
71+
public fun box(): String
72+
/* ACCESSOR use-site */ access$foo<Any?>($this = this, x = x)
73+
/* ACCESSOR use-site */ access$baz<Any?, Any?>($this = this, x = x, y = y)
74+
/* ACCESSOR use-site */ access$baz<Any?, Any?>($this = this, x = x, y = y)
75+
/* ACCESSOR use-site */ access$barB<Any?, Any?>($this = this, x = x, y = y)
76+
/* ACCESSOR use-site */ access$barB<Any?, Any?>($this = this, x = x, y = y)
77+
/* ACCESSOR use-site */ access$barD<Any?>($this = this, x = x)
78+
/* ACCESSOR use-site */ access$foo<Any?>($this = this, x = x)
79+
/* ACCESSOR use-site */ access$baz<Any?, Any?>($this = this, x = x, y = y)
80+
/* ACCESSOR use-site */ access$baz<Any?, Any?>($this = this, x = x, y = y)
81+
/* ACCESSOR use-site */ access$barB<Any?, Any?>($this = this, x = x, y = y)
82+
/* ACCESSOR use-site */ access$barB<Any?, Any?>($this = this, x = x, y = y)
83+
/* ACCESSOR use-site */ access$barE($this = this, x = x)
84+
/* ACCESSOR use-site */ access$barF($this = this, x = x)
85+
/* ACCESSOR use-site */ access$listHead<Any?>($this = this, xs = xs)
86+
/* ACCESSOR use-site */ access$foo<Any?>($this = this, x = x)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// WITH_STDLIB
2+
3+
open class A<T> {
4+
private fun foo(x: T) = x
5+
internal inline fun callFoo(x: T) = foo(x)
6+
7+
private fun <U> baz(x: T, y: U) = x to y
8+
internal inline fun <U> callBaz(x: T, y: U) = baz(x, y)
9+
10+
inner class B<S> {
11+
private fun barB(x: T, y: S) = x to y
12+
internal inline fun callBarB(x: T, y: S) = barB(x, y)
13+
}
14+
15+
inner class C<S> private constructor(val x: S) {
16+
internal inline fun copy() = C<Int>(42)
17+
}
18+
19+
companion object Companion {
20+
private fun barCompanion(x: Any) = x
21+
internal inline fun callBarCompanion(x: Any) = barCompanion(x)
22+
}
23+
24+
class Nested {
25+
private fun barNested(x: Any) = x
26+
internal inline fun callBarNested(x: Any) = barNested(x)
27+
}
28+
29+
inner class D : A<Int>() {
30+
private fun barD(x: T) = x
31+
internal inline fun callBarD(x: T) = barD(x)
32+
}
33+
34+
private fun listHead(xs: List<T>): T = xs.first()
35+
internal inline fun callListHead(xs: List<T>) = listHead(xs)
36+
37+
internal inline fun <reified R> callFooReified(x: T) = foo(x) as? R
38+
}
39+
40+
class E : A<Int>() {
41+
private fun barE(x: Int) = x
42+
internal inline fun callBarE(x: Int) = barE(x)
43+
44+
inner class F {
45+
private fun barF(x: Int) = x
46+
internal inline fun callBarF(x: Int) = barF(x)
47+
}
48+
}
49+
50+
fun box(): String {
51+
var res = ""
52+
res += A<String>().callFoo("OK1 ")
53+
res += A<String>().callBaz("OK2 ", "NO2 ").first
54+
res += A<String>().callBaz("NO3 ", "OK3 ").second
55+
res += A<String>().B<String>().callBarB("OK4 ", "NO4 ").first
56+
res += A<String>().B<String>().callBarB("NO5", "OK5 ").second
57+
res += A<String>().D().callBarD("OK6 ")
58+
res += "OK" + A<String>().D().callFoo(7) + " "
59+
res += "OK" + A<String>().D().callBaz(8, -1).first + " "
60+
res += "OK" + A<String>().D().callBaz(-1, 9).second + " "
61+
res += "OK" + A<String>().D().B<Int>().callBarB(10, -1).first + " "
62+
res += "OK" + A<String>().D().B<Int>().callBarB(-1, 11).second + " "
63+
res += "OK" + E().callBarE(12) + " "
64+
res += "OK" + E().F().callBarF(13) + " "
65+
res += A<String>().callListHead(listOf("OK14")) + " "
66+
res += A<String>().callFooReified<String>("OK15")
67+
if (res != "OK1 OK2 OK3 OK4 OK5 OK6 OK7 OK8 OK9 OK10 OK11 OK12 OK13 OK14 OK15") return res
68+
else return "OK"
69+
}

js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsKlibSyntheticAccessorTestGenerated.java

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

js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsKlibSyntheticAccessorsBoxTestGenerated.java

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

wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/WasmJsSynthAccBoxTestGenerated.java

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

wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/WasmJsSynthAccTestGenerated.java

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

0 commit comments

Comments
 (0)