JS: inline safe calls

#KT-6912 fixed
This commit is contained in:
Alexey Tsvetkov
2016-03-06 18:58:15 +03:00
parent 956e9f3847
commit df3f163ee2
4 changed files with 28 additions and 4 deletions
+6 -3
View File
@@ -1,5 +1,8 @@
= CHANGELOG =
# CHANGELOG
== 1.1 ==
## 1.1
== 1.0.2 ==
## 1.0.2
### JS
- Safe calls (`x?.let { it }`) are now inlined
@@ -299,6 +299,12 @@ public class InlineJsTestGenerated extends AbstractInlineJsTest {
doTest(fileName);
}
@TestMetadata("safeCall.kt")
public void testSafeCall() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/inline/cases/safeCall.kt");
doTest(fileName);
}
@TestMetadata("severalClosures.kt")
public void testSeveralClosures() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/inline/cases/severalClosures.kt");
@@ -55,7 +55,7 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
JsExpression callExpression = (new CallExpressionTranslator(expression, receiver, context)).translate();
if (!resolvedCall.isSafeCall() && shouldBeInlined(expression, context)) {
if (shouldBeInlined(expression, context)) {
setInlineCallMetadata(callExpression, expression, resolvedCall, context);
}
+15
View File
@@ -0,0 +1,15 @@
package foo
// CHECK_CONTAINS_NO_CALLS: sum
inline fun <T : Any, R> T.doLet(f: (T) -> R): R = f(this)
private fun sum(x: Int?, y: Int): Int =
x?.doLet { it + y } ?: 0
fun box(): String {
assertEquals(5, sum(2, 3))
assertEquals(0, sum(null, 3))
return "OK"
}