Skip to content

Commit c8a4ba1

Browse files
AlexK0Space Team
authored and
Space Team
committed
[JS IR] Don't check an interface method default impl during JS translation
We do not need to check a default implementation of the interface during the translation to JS because it must be checked before. Moreover, this check breaks the produced JS code if IR is partial loaded, e.g. during the incremental rebuild. ^KT-55716 Fixed
1 parent eaa61d2 commit c8a4ba1

File tree

20 files changed

+281
-2
lines changed

20 files changed

+281
-2
lines changed

compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ fun translateCall(
162162
Pair(function, superQualifier.owner)
163163
}
164164

165-
val callRef = if (klass.isInterface && target.body != null) {
166-
JsNameRef(Namer.CALL_FUNCTION, JsNameRef(context.getNameForStaticDeclaration(target)))
165+
val callRef = if (klass.isInterface) {
166+
val nameForStaticDeclaration = context.getNameForStaticDeclaration(target)
167+
JsNameRef(Namer.CALL_FUNCTION, JsNameRef(nameForStaticDeclaration))
167168
} else {
168169
val qualifierName = context.getNameForClass(klass).makeRef()
169170
val targetName = context.getNameForMemberFunction(target)

js/js.tests/tests-gen/org/jetbrains/kotlin/incremental/InvalidationTestGenerated.java

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class ClassA : Interface {
2+
override var someVar: Int?
3+
get() = super.someVar
4+
set(value) {
5+
super.someVar = value
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class ClassA : Interface {
2+
override var someVar: Int?
3+
get() = 1
4+
set(value) {
5+
super.someVar = value
6+
}
7+
8+
override val someValue: Int
9+
get() = super.someValue
10+
11+
override fun someFunction(): Int = super.someFunction()
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class ClassB : Interface {
2+
override var someVar: Int?
3+
get() = super.someVar
4+
set(value) {
5+
super.someVar = value
6+
}
7+
8+
val x = 1
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ClassB : Interface {
2+
val x = 3
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class ClassB : Interface {
2+
val x = 3
3+
4+
override val someValue: Int
5+
get() = super.someValue + 1
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class ClassB : Interface {
2+
val x = 3
3+
4+
override val someValue: Int
5+
get() = super.someValue + 1
6+
7+
override fun someFunction(): Int = super.someFunction() + 1
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
private var myProperty: Int? = null
2+
3+
interface Interface {
4+
var someVar: Int?
5+
get() = myProperty
6+
set(value) {
7+
myProperty = value
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
private var myProperty: Int? = null
2+
3+
interface Interface {
4+
var someVar: Int?
5+
get() = myProperty?.let {
6+
if (it == 1) {
7+
it + 1
8+
} else {
9+
it
10+
}
11+
}
12+
set(value) {
13+
myProperty = value
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
private var myProperty: Int? = null
2+
3+
interface Interface {
4+
var someVar: Int?
5+
get() = myProperty?.let {
6+
if (it == 1 || it == 3) {
7+
it + 1
8+
} else {
9+
it
10+
}
11+
}
12+
set(value) {
13+
myProperty = value
14+
}
15+
16+
val someValue: Int
17+
get() = 1
18+
19+
fun someFunction(): Int = someValue
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
STEP 0:
2+
modifications:
3+
U : ClassA.0.kt -> ClassA.kt
4+
U : ClassB.0.kt -> ClassB.kt
5+
U : Interface.0.kt -> Interface.kt
6+
added file: ClassA.kt, ClassB.kt, Interface.kt
7+
STEP 1:
8+
updated exports: ClassB.kt
9+
STEP 2:
10+
modifications:
11+
U : Interface.2.kt -> Interface.kt
12+
modified ir: Interface.kt
13+
STEP 3:
14+
modifications:
15+
U : ClassB.3.kt -> ClassB.kt
16+
modified ir: ClassB.kt
17+
updated exports: ClassB.kt
18+
STEP 4:
19+
modifications:
20+
U : Interface.4.kt -> Interface.kt
21+
modified ir: Interface.kt
22+
STEP 5:
23+
updated exports: Interface.kt, ClassB.kt
24+
STEP 6:
25+
modifications:
26+
U : ClassB.6.kt -> ClassB.kt
27+
modified ir: ClassB.kt
28+
updated exports: Interface.kt
29+
STEP 7:
30+
modifications:
31+
U : ClassB.7.kt -> ClassB.kt
32+
modified ir: ClassB.kt
33+
STEP 8:
34+
modifications:
35+
U : ClassA.8.kt -> ClassA.kt
36+
modified ir: ClassA.kt
37+
STEP 9..10:
38+
updated exports: ClassA.kt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fun box(stepId: Int): String {
2+
val x = test()
3+
if (x != stepId) {
4+
return "Fail: $x != $stepId"
5+
}
6+
return "OK"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
STEP 0:
2+
dependencies: lib1
3+
modifications:
4+
U : test.0.kt -> test.kt
5+
added file: m.kt, test.kt
6+
STEP 1:
7+
dependencies: lib1
8+
modifications:
9+
U : test.1.kt -> test.kt
10+
modified ir: test.kt
11+
STEP 2:
12+
dependencies: lib1
13+
STEP 3:
14+
dependencies: lib1
15+
updated imports: test.kt
16+
STEP 4:
17+
dependencies: lib1
18+
STEP 5:
19+
dependencies: lib1
20+
modifications:
21+
U : test.5.kt -> test.kt
22+
modified ir: test.kt
23+
STEP 6:
24+
dependencies: lib1
25+
STEP 7:
26+
dependencies: lib1
27+
updated imports: test.kt
28+
STEP 8:
29+
dependencies: lib1
30+
STEP 9:
31+
dependencies: lib1
32+
modifications:
33+
U : test.9.kt -> test.kt
34+
modified ir: test.kt
35+
STEP 10:
36+
dependencies: lib1
37+
modifications:
38+
U : test.10.kt -> test.kt
39+
modified ir: test.kt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
private fun testClassA(): Int {
2+
val a = ClassA()
3+
a.someVar = 0
4+
return a.someVar!!
5+
}
6+
7+
fun test(): Int {
8+
return testClassA()
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
private fun testClassA(): Int {
2+
val a = ClassA()
3+
a.someVar = 0
4+
return a.someVar!!
5+
}
6+
7+
private fun testClassB(): Int {
8+
val b = ClassB()
9+
b.someVar = b.x
10+
return b.someVar!!
11+
}
12+
13+
fun test(): Int {
14+
val b = testClassB()
15+
val a = testClassA()
16+
return b + a
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
private fun testClassA(): Int {
2+
val a = ClassA()
3+
a.someVar = 0
4+
return a.someVar!! + a.someFunction() + a.someValue
5+
}
6+
7+
private fun testClassB(): Int {
8+
val b = ClassB()
9+
b.someVar = b.x
10+
return b.someVar!! + b.someFunction()
11+
}
12+
13+
fun test(): Int {
14+
val b = testClassB()
15+
val a = testClassA()
16+
return b + a
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
private fun testClassA(): Int {
2+
val a = ClassA()
3+
a.someVar = 0
4+
return a.someVar!!
5+
}
6+
7+
private fun testClassB(): Int {
8+
val b = ClassB()
9+
b.someVar = b.x
10+
return b.someVar!! + b.someFunction()
11+
}
12+
13+
fun test(): Int {
14+
val b = testClassB()
15+
val a = testClassA()
16+
return b + a
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
private fun testClassA(): Int {
2+
val a = ClassA()
3+
a.someVar = 0
4+
return a.someVar!! + a.someFunction()
5+
}
6+
7+
private fun testClassB(): Int {
8+
val b = ClassB()
9+
b.someVar = b.x
10+
return b.someVar!! + b.someFunction()
11+
}
12+
13+
fun test(): Int {
14+
val b = testClassB()
15+
val a = testClassA()
16+
return b + a
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
MODULES: lib1, main
2+
3+
STEP 0..3:
4+
libs: lib1, main
5+
dirty js: lib1, main
6+
STEP 4:
7+
libs: lib1, main
8+
dirty js: lib1
9+
STEP 5:
10+
libs: lib1, main
11+
dirty js: lib1, main
12+
STEP 6:
13+
libs: lib1, main
14+
dirty js: lib1
15+
STEP 7:
16+
libs: lib1, main
17+
dirty js: lib1, main
18+
STEP 8:
19+
libs: lib1, main
20+
dirty js: lib1
21+
STEP 9..10:
22+
libs: lib1, main
23+
dirty js: lib1, main

0 commit comments

Comments
 (0)