KJS: fix compiler crash when using inline function inside string template

#KT-12586 Fixed
This commit is contained in:
Zalim Bashorov
2016-12-02 22:09:28 +03:00
parent 8ccc00f3d4
commit b42fe06933
3 changed files with 17 additions and 3 deletions
@@ -3680,6 +3680,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
doTest(fileName);
}
@TestMetadata("inlineCallInsideStringTemplate.kt")
public void testInlineCallInsideStringTemplate() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inline/inlineCallInsideStringTemplate.kt");
doTest(fileName);
}
@TestMetadata("inlineCallNoInline.kt")
public void testInlineCallNoInline() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inline/inlineCallNoInline.kt");
@@ -20,6 +20,7 @@ import com.google.dart.compiler.backend.js.ast.JsExpression;
import com.google.dart.compiler.backend.js.ast.JsInvocation;
import com.google.dart.compiler.backend.js.ast.JsNameRef;
import com.google.dart.compiler.backend.js.ast.JsNumberLiteral;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsKt;
@@ -32,8 +33,6 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.types.KotlinType;
import java.util.Collections;
import static org.jetbrains.kotlin.js.translate.utils.ErrorReportingUtils.message;
import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.sum;
@@ -90,7 +89,7 @@ public final class StringTemplateTranslator extends AbstractTranslator {
KotlinType type = context().bindingContext().getType(entryExpression);
if (type == null || type.isMarkedNullable()) {
append(TopLevelFIF.TO_STRING.apply((JsExpression) null, Collections.singletonList(translatedExpression), context()));
append(TopLevelFIF.TO_STRING.apply((JsExpression) null, new SmartList<JsExpression>(translatedExpression), context()));
}
else if (mustCallToString(type)) {
append(new JsInvocation(new JsNameRef("toString", translatedExpression)));
@@ -0,0 +1,9 @@
package foo
inline fun foo(): Any? = "foo()"
fun box(): String {
assertEquals("foo()", "${foo()}")
assertEquals("aaa foo() bb", "aaa ${foo()} bb")
return "OK"
}