JS: do not alias 'this' literal in a receiver position

This commit is contained in:
Alexey Tsvetkov
2015-04-21 18:00:52 +03:00
parent 6b09b4c2b6
commit 900147385d
3 changed files with 26 additions and 1 deletions
@@ -68,7 +68,7 @@ class FunctionInlineMutator private (private val call: JsInvocation, private val
if (!hasThisReference(body)) return
var thisReplacement = getThisReplacement(call)
if (thisReplacement == null) return
if (thisReplacement == null || thisReplacement is JsLiteral.JsThisRef) return
if (thisReplacement!!.needToAlias()) {
val thisName = namingContext.getFreshName(getThisAlias())
@@ -53,6 +53,12 @@ public class InlineSizeReductionTestGenerated extends AbstractInlineSizeReductio
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")
public void testValAssignment() throws Exception {
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"
}