diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index 33f09d5df19..459c554df9a 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -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"); diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/StringTemplateTranslator.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/StringTemplateTranslator.java index e42ec00cd38..1e754c17c26 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/StringTemplateTranslator.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/StringTemplateTranslator.java @@ -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(translatedExpression), context())); } else if (mustCallToString(type)) { append(new JsInvocation(new JsNameRef("toString", translatedExpression))); diff --git a/js/js.translator/testData/box/inline/inlineCallInsideStringTemplate.kt b/js/js.translator/testData/box/inline/inlineCallInsideStringTemplate.kt new file mode 100644 index 00000000000..7c652755009 --- /dev/null +++ b/js/js.translator/testData/box/inline/inlineCallInsideStringTemplate.kt @@ -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" +}