Skip to content

Commit

Permalink
[JS IR] Don't check an interface method default impl during JS transl…
Browse files Browse the repository at this point in the history
…ation

 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
  • Loading branch information
AlexK0 authored and qodana-bot committed Jan 20, 2023
1 parent eaa61d2 commit c8a4ba1
Show file tree
Hide file tree
Showing 20 changed files with 281 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ fun translateCall(
Pair(function, superQualifier.owner)
}

val callRef = if (klass.isInterface && target.body != null) {
JsNameRef(Namer.CALL_FUNCTION, JsNameRef(context.getNameForStaticDeclaration(target)))
val callRef = if (klass.isInterface) {
val nameForStaticDeclaration = context.getNameForStaticDeclaration(target)
JsNameRef(Namer.CALL_FUNCTION, JsNameRef(nameForStaticDeclaration))
} else {
val qualifierName = context.getNameForClass(klass).makeRef()
val targetName = context.getNameForMemberFunction(target)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ClassA : Interface {
override var someVar: Int?
get() = super.someVar
set(value) {
super.someVar = value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class ClassA : Interface {
override var someVar: Int?
get() = 1
set(value) {
super.someVar = value
}

override val someValue: Int
get() = super.someValue

override fun someFunction(): Int = super.someFunction()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ClassB : Interface {
override var someVar: Int?
get() = super.someVar
set(value) {
super.someVar = value
}

val x = 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ClassB : Interface {
val x = 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ClassB : Interface {
val x = 3

override val someValue: Int
get() = super.someValue + 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ClassB : Interface {
val x = 3

override val someValue: Int
get() = super.someValue + 1

override fun someFunction(): Int = super.someFunction() + 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
private var myProperty: Int? = null

interface Interface {
var someVar: Int?
get() = myProperty
set(value) {
myProperty = value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
private var myProperty: Int? = null

interface Interface {
var someVar: Int?
get() = myProperty?.let {
if (it == 1) {
it + 1
} else {
it
}
}
set(value) {
myProperty = value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
private var myProperty: Int? = null

interface Interface {
var someVar: Int?
get() = myProperty?.let {
if (it == 1 || it == 3) {
it + 1
} else {
it
}
}
set(value) {
myProperty = value
}

val someValue: Int
get() = 1

fun someFunction(): Int = someValue
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
STEP 0:
modifications:
U : ClassA.0.kt -> ClassA.kt
U : ClassB.0.kt -> ClassB.kt
U : Interface.0.kt -> Interface.kt
added file: ClassA.kt, ClassB.kt, Interface.kt
STEP 1:
updated exports: ClassB.kt
STEP 2:
modifications:
U : Interface.2.kt -> Interface.kt
modified ir: Interface.kt
STEP 3:
modifications:
U : ClassB.3.kt -> ClassB.kt
modified ir: ClassB.kt
updated exports: ClassB.kt
STEP 4:
modifications:
U : Interface.4.kt -> Interface.kt
modified ir: Interface.kt
STEP 5:
updated exports: Interface.kt, ClassB.kt
STEP 6:
modifications:
U : ClassB.6.kt -> ClassB.kt
modified ir: ClassB.kt
updated exports: Interface.kt
STEP 7:
modifications:
U : ClassB.7.kt -> ClassB.kt
modified ir: ClassB.kt
STEP 8:
modifications:
U : ClassA.8.kt -> ClassA.kt
modified ir: ClassA.kt
STEP 9..10:
updated exports: ClassA.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fun box(stepId: Int): String {
val x = test()
if (x != stepId) {
return "Fail: $x != $stepId"
}
return "OK"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
STEP 0:
dependencies: lib1
modifications:
U : test.0.kt -> test.kt
added file: m.kt, test.kt
STEP 1:
dependencies: lib1
modifications:
U : test.1.kt -> test.kt
modified ir: test.kt
STEP 2:
dependencies: lib1
STEP 3:
dependencies: lib1
updated imports: test.kt
STEP 4:
dependencies: lib1
STEP 5:
dependencies: lib1
modifications:
U : test.5.kt -> test.kt
modified ir: test.kt
STEP 6:
dependencies: lib1
STEP 7:
dependencies: lib1
updated imports: test.kt
STEP 8:
dependencies: lib1
STEP 9:
dependencies: lib1
modifications:
U : test.9.kt -> test.kt
modified ir: test.kt
STEP 10:
dependencies: lib1
modifications:
U : test.10.kt -> test.kt
modified ir: test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
private fun testClassA(): Int {
val a = ClassA()
a.someVar = 0
return a.someVar!!
}

fun test(): Int {
return testClassA()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
private fun testClassA(): Int {
val a = ClassA()
a.someVar = 0
return a.someVar!!
}

private fun testClassB(): Int {
val b = ClassB()
b.someVar = b.x
return b.someVar!!
}

fun test(): Int {
val b = testClassB()
val a = testClassA()
return b + a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
private fun testClassA(): Int {
val a = ClassA()
a.someVar = 0
return a.someVar!! + a.someFunction() + a.someValue
}

private fun testClassB(): Int {
val b = ClassB()
b.someVar = b.x
return b.someVar!! + b.someFunction()
}

fun test(): Int {
val b = testClassB()
val a = testClassA()
return b + a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
private fun testClassA(): Int {
val a = ClassA()
a.someVar = 0
return a.someVar!!
}

private fun testClassB(): Int {
val b = ClassB()
b.someVar = b.x
return b.someVar!! + b.someFunction()
}

fun test(): Int {
val b = testClassB()
val a = testClassA()
return b + a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
private fun testClassA(): Int {
val a = ClassA()
a.someVar = 0
return a.someVar!! + a.someFunction()
}

private fun testClassB(): Int {
val b = ClassB()
b.someVar = b.x
return b.someVar!! + b.someFunction()
}

fun test(): Int {
val b = testClassB()
val a = testClassA()
return b + a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MODULES: lib1, main

STEP 0..3:
libs: lib1, main
dirty js: lib1, main
STEP 4:
libs: lib1, main
dirty js: lib1
STEP 5:
libs: lib1, main
dirty js: lib1, main
STEP 6:
libs: lib1, main
dirty js: lib1
STEP 7:
libs: lib1, main
dirty js: lib1, main
STEP 8:
libs: lib1, main
dirty js: lib1
STEP 9..10:
libs: lib1, main
dirty js: lib1, main

0 comments on commit c8a4ba1

Please sign in to comment.