From 900147385dd3f87b8b6b28e840f34b3f5a6825ec Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Tue, 21 Apr 2015 18:00:52 +0300 Subject: [PATCH] JS: do not alias 'this' literal in a receiver position --- .../kotlin/js/inline/FunctionInlineMutator.kt | 2 +- .../InlineSizeReductionTestGenerated.java | 6 ++++++ .../inlineSizeReduction/cases/this.kt | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 js/js.translator/testData/inlineSizeReduction/cases/this.kt diff --git a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionInlineMutator.kt b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionInlineMutator.kt index 9dfd215cd5a..b805e95c11e 100644 --- a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionInlineMutator.kt +++ b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionInlineMutator.kt @@ -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()) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSizeReductionTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSizeReductionTestGenerated.java index 2ef384a2a07..0f622f0aa01 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSizeReductionTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSizeReductionTestGenerated.java @@ -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"); diff --git a/js/js.translator/testData/inlineSizeReduction/cases/this.kt b/js/js.translator/testData/inlineSizeReduction/cases/this.kt new file mode 100644 index 00000000000..c13c52914f0 --- /dev/null +++ b/js/js.translator/testData/inlineSizeReduction/cases/this.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" +} \ No newline at end of file