JS: inline safe calls
#KT-6912 fixed
This commit is contained in:
+6
-3
@@ -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");
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user