JS: decomposition should preserve 'this' context with invocations
#KT-7502 fixed
This commit is contained in:
@@ -25,6 +25,7 @@ import kotlin.platform.platformStatic
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer
|
||||
|
||||
/**
|
||||
* If inline function consists of multiple statements,
|
||||
@@ -259,12 +260,21 @@ class ExpressionDecomposer private (
|
||||
}
|
||||
|
||||
private fun Callable.process() {
|
||||
val matchedIndices = arguments.indicesOfExtractable
|
||||
var matchedIndices = arguments.indicesOfExtractable
|
||||
if (!matchedIndices.hasNext()) return
|
||||
|
||||
qualifier = accept(qualifier)
|
||||
if (qualifier in containsNodeWithSideEffect) {
|
||||
qualifier = qualifier.extractToTemporary()
|
||||
val callee = qualifier as? JsNameRef
|
||||
val receiver = callee?.qualifier
|
||||
|
||||
if (callee != null && receiver != null && receiver in containsNodeWithSideEffect) {
|
||||
val receiverTmp = receiver.extractToTemporary()
|
||||
callee.qualifier = receiverTmp
|
||||
}
|
||||
else {
|
||||
qualifier = qualifier.extractToTemporary()
|
||||
}
|
||||
}
|
||||
|
||||
processByIndices(arguments, matchedIndices)
|
||||
|
||||
+12
@@ -197,6 +197,18 @@ public class InlineEvaluationOrderTestGenerated extends AbstractInlineEvaluation
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("methodCallQualifierWithSideEffect.kt")
|
||||
public void testMethodCallQualifierWithSideEffect() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineEvaluationOrder/cases/methodCallQualifierWithSideEffect.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("methodInlineCallQualifierWithSideEffect.kt")
|
||||
public void testMethodInlineCallQualifierWithSideEffect() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineEvaluationOrder/cases/methodInlineCallQualifierWithSideEffect.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("multiDeclaration.kt")
|
||||
public void testMultiDeclaration() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineEvaluationOrder/cases/multiDeclaration.kt");
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
// Test for KT-7502
|
||||
|
||||
class A(val value: Int) {
|
||||
fun plus(num: Int): Int = this.value + num
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(15, A(fizz(5)).plus(buzz(10)))
|
||||
assertEquals("fizz(5);buzz(10);", pullLog())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
// Test for KT-7502
|
||||
// CHECK_NOT_CALLED: plus
|
||||
|
||||
class A(val value: Int) {
|
||||
inline fun plus(num: Int): Int = this.value + num
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(15, A(fizz(5)).plus(buzz(10)))
|
||||
assertEquals("fizz(5);buzz(10);", pullLog())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user