JS: do not alias 'this' literal in a receiver position
This commit is contained in:
@@ -68,7 +68,7 @@ class FunctionInlineMutator private (private val call: JsInvocation, private val
|
|||||||
if (!hasThisReference(body)) return
|
if (!hasThisReference(body)) return
|
||||||
|
|
||||||
var thisReplacement = getThisReplacement(call)
|
var thisReplacement = getThisReplacement(call)
|
||||||
if (thisReplacement == null) return
|
if (thisReplacement == null || thisReplacement is JsLiteral.JsThisRef) return
|
||||||
|
|
||||||
if (thisReplacement!!.needToAlias()) {
|
if (thisReplacement!!.needToAlias()) {
|
||||||
val thisName = namingContext.getFreshName(getThisAlias())
|
val thisName = namingContext.getFreshName(getThisAlias())
|
||||||
|
|||||||
+6
@@ -53,6 +53,12 @@ public class InlineSizeReductionTestGenerated extends AbstractInlineSizeReductio
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("this.kt")
|
||||||
|
public void testThis() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineSizeReduction/cases/this.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("valAssignment.kt")
|
@TestMetadata("valAssignment.kt")
|
||||||
public void testValAssignment() throws Exception {
|
public void testValAssignment() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineSizeReduction/cases/valAssignment.kt");
|
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineSizeReduction/cases/valAssignment.kt");
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
// CHECK_CONTAINS_NO_CALLS: test
|
||||||
|
// CHECK_VARS_COUNT: function=test count=0
|
||||||
|
|
||||||
|
class A(val x: Int) {
|
||||||
|
inline fun f(): Int = x
|
||||||
|
|
||||||
|
inline fun ff(): Int = f()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(a: A): Int = a.ff()
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
assertEquals(1, test(A(1)))
|
||||||
|
assertEquals(2, test(A(2)))
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user