Skip to content

Commit 159df79

Browse files
committed
JS: bound callable references (KT-13573).
1 parent dc1e3ae commit 159df79

File tree

28 files changed

+474
-121
lines changed

28 files changed

+474
-121
lines changed

compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// TODO investigate should it be ran for JS or not
2-
// IGNORE_BACKEND: JS
3-
41
class A {
52
companion object {
63
fun ok() = "OK"

compiler/testData/codegen/box/callableReference/bound/enumEntryMember.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// TODO: muted automatically, investigate should it be ran for JS or not
21
// IGNORE_BACKEND: JS
3-
42
enum class E {
53
A, B;
64

compiler/testData/codegen/box/callableReference/bound/inline/simple.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// TODO: muted automatically, investigate should it be ran for JS or not
2-
// IGNORE_BACKEND: JS
3-
41
inline fun foo(x: () -> String) = x()
52

63
fun String.id() = this

compiler/testData/codegen/box/callableReference/bound/inline/simpleVal.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// TODO: muted automatically, investigate should it be ran for JS or not
2-
// IGNORE_BACKEND: JS
3-
41
inline fun go(f: () -> String) = f()
52

63
fun String.id(): String = this

compiler/testData/codegen/box/callableReference/bound/kCallableNameIntrinsic.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
// TODO: muted automatically, investigate should it be ran for JS or not
1+
// Enable when callable references to builtin members is supported
22
// IGNORE_BACKEND: JS
3-
4-
// See KT-12995
5-
63
fun box(): String {
74
var state = 0
85
val name = (state++)::toString.name

compiler/testData/codegen/box/callableReference/bound/kt12738.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// TODO: muted automatically, investigate should it be ran for JS or not
1+
// Enable when callable references to builtin members is supported
22
// IGNORE_BACKEND: JS
3-
43
fun <T> get(t: T): () -> String {
54
return t::toString
65
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class A(var v: Int) {
2+
fun f(x: Int) = x * v
3+
}
4+
5+
fun A.g(x: Int) = x * f(x);
6+
7+
var A.w: Int
8+
get() = 1000 * v
9+
set(c: Int) {
10+
v = c + 10
11+
}
12+
13+
object F {
14+
var u = 0
15+
}
16+
17+
fun box(): String {
18+
val a = A(5)
19+
20+
val av = a::v
21+
if (av() != 5) return "fail1: ${av()}"
22+
if (av.get() != 5) return "fail2: ${av.get()}"
23+
av.set(7)
24+
if (a.v != 7) return "fail3: ${a.v}"
25+
26+
val af = a::f
27+
if (af(10) != 70) return "fail4: ${af(10)}"
28+
29+
val ag = a::g
30+
if (ag(10) != 700) return "fail5: ${ag(10)}"
31+
32+
val aw = a::w
33+
if (aw() != 7000) return "fail6: ${aw()}"
34+
if (aw.get() != 7000) return "fail7: ${aw.get()}"
35+
aw.set(5)
36+
if (a.v != 15) return "fail8: ${a.v}"
37+
38+
val fu = F::u
39+
if (fu() != 0) return "fail9: ${fu()}"
40+
if (fu.get() != 0) return "fail10: ${fu.get()}"
41+
fu.set(8)
42+
if (F.u != 8) return "fail11: ${F.u}"
43+
44+
val x = 100
45+
46+
fun A.lf() = v * x;
47+
val alf = a::lf
48+
if (alf() != 1500) return "fail9: ${alf()}"
49+
50+
return "OK"
51+
}

compiler/testData/codegen/box/callableReference/bound/nullReceiver.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// TODO: investigate should it be ran for JS or not
2-
// IGNORE_BACKEND: JS
3-
4-
// See https://youtrack.jetbrains.com/issue/KT-14939
5-
61
val String?.ok: String
72
get() = "OK"
83

compiler/testData/codegen/box/callableReference/bound/objectReceiver.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// TODO investigate should it be ran for JS or not
2-
// IGNORE_BACKEND: JS
3-
41
object Singleton {
52
fun ok() = "OK"
63
}

compiler/testData/codegen/box/callableReference/bound/simpleFunction.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// TODO: muted automatically, investigate should it be ran for JS or not
1+
// Enable when callable references to builtin members is supported
22
// IGNORE_BACKEND: JS
3-
43
fun box(): String {
54
val f = "KOTLIN"::get
65
return "${f(1)}${f(0)}"

compiler/testData/codegen/box/callableReference/bound/simpleProperty.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// TODO: muted automatically, investigate should it be ran for JS or not
1+
// Enable when callable references to builtin members are supported.
22
// IGNORE_BACKEND: JS
33

44
fun box(): String {

compiler/testData/codegen/box/callableReference/bound/syntheticExtensionOnLHS.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// TODO: muted automatically, investigate should it be ran for JS or not
2-
// IGNORE_BACKEND: JS
3-
1+
// TARGET_BACKEND: JVM
42
// WITH_RUNTIME
53
// FILE: A.java
64

compiler/testData/codegen/boxInline/callableReference/bound/intrinsic.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Enable when callable references to builtin members is supported
2+
// IGNORE_BACKEND: JS
13
// FILE: 1.kt
24

35
package test

compiler/testData/codegen/boxInline/callableReference/classLevel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Enable when using lambdas as extension lambdas is supported (KT-13312)
2+
// IGNORE_BACKEND: JS
13
// FILE: 1.kt
24

35
package test

compiler/testData/codegen/boxInline/callableReference/classLevel2.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Enable when using lambdas as extension lambdas is supported (KT-13312)
2+
// IGNORE_BACKEND: JS
13
// FILE: 1.kt
24

35
package test

compiler/testData/codegen/boxInline/callableReference/intrinsic.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Enable when callable references to builtin members and using lambdas as extension lambdas (KT-13312) is supported
2+
// IGNORE_BACKEND: JS
13
// FILE: 1.kt
24

35
package test

compiler/testData/codegen/boxInline/callableReference/propertyIntrinsic.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Enable when callable references to builtin members and using lambdas as extension lambdas (KT-13312) is supported
2+
// IGNORE_BACKEND: JS
13
// FILE: 1.kt
24

35
package test

compiler/testData/codegen/boxInline/callableReference/topLevelExtension.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Enable when using lambdas as extension lambdas is supported (KT-13312)
2+
// IGNORE_BACKEND: JS
13
// FILE: 1.kt
24

35
package test

compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,12 @@ public void testKt12738() throws Exception {
15251525
doTest(fileName);
15261526
}
15271527

1528+
@TestMetadata("multiCase.kt")
1529+
public void testMultiCase() throws Exception {
1530+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/multiCase.kt");
1531+
doTest(fileName);
1532+
}
1533+
15281534
@TestMetadata("nullReceiver.kt")
15291535
public void testNullReceiver() throws Exception {
15301536
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/nullReceiver.kt");

compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,12 @@ public void testKt12738() throws Exception {
15251525
doTest(fileName);
15261526
}
15271527

1528+
@TestMetadata("multiCase.kt")
1529+
public void testMultiCase() throws Exception {
1530+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/multiCase.kt");
1531+
doTest(fileName);
1532+
}
1533+
15281534
@TestMetadata("nullReceiver.kt")
15291535
public void testNullReceiver() throws Exception {
15301536
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/nullReceiver.kt");

generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,13 +1200,17 @@ fun main(args: Array<String>) {
12001200
model("codegen/boxInline/nonLocalReturns/", targetBackend = TargetBackend.JS)
12011201
}
12021202

1203-
testClass<AbstractPropertyAccessorsInlineTests>() {
1203+
testClass<AbstractPropertyAccessorsInlineTests> {
12041204
model("codegen/boxInline/property/", targetBackend = TargetBackend.JS)
12051205
}
12061206

1207-
testClass<AbstractNoInlineTests>() {
1207+
testClass<AbstractNoInlineTests> {
12081208
model("codegen/boxInline/noInline/", targetBackend = TargetBackend.JS)
12091209
}
1210+
1211+
testClass<AbstractCallableReferenceInlineTests> {
1212+
model("codegen/boxInline/callableReference/", targetBackend = TargetBackend.JS)
1213+
}
12101214
}
12111215
}
12121216

0 commit comments

Comments
 (0)