JS: make string template optimization more conservative
See KT-18548
This commit is contained in:
committed by
Alexey Andreev
parent
ca014468ee
commit
b852f73dd2
@@ -3175,6 +3175,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/expression/stringTemplates"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/expression/stringTemplates"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonStrings.kt")
|
||||||
|
public void testNonStrings() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/expression/stringTemplates/nonStrings.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectWithToString.kt")
|
@TestMetadata("objectWithToString.kt")
|
||||||
public void testObjectWithToString() throws Exception {
|
public void testObjectWithToString() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/expression/stringTemplates/objectWithToString.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/expression/stringTemplates/objectWithToString.kt");
|
||||||
|
|||||||
+4
-9
@@ -112,16 +112,11 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
|||||||
|
|
||||||
private boolean mustCallToString(@NotNull KotlinType type) {
|
private boolean mustCallToString(@NotNull KotlinType type) {
|
||||||
Name typeName = DescriptorUtilsKt.getNameIfStandardType(type);
|
Name typeName = DescriptorUtilsKt.getNameIfStandardType(type);
|
||||||
if (typeName != null) {
|
//TODO: this is a hacky optimization, should use some generic approach
|
||||||
//TODO: this is a hacky optimization, should use some generic approach
|
if (typeName != null && NamePredicate.STRING.test(typeName)) {
|
||||||
if (NamePredicate.STRING.test(typeName)) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (NamePredicate.PRIMITIVE_NUMBERS.test(typeName)) {
|
|
||||||
return resultingExpression == null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return expressionEntries.length == 1;
|
return resultingExpression == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// EXPECTED_REACHABLE_NODES: 1024
|
||||||
|
fun box(): String {
|
||||||
|
val x = foo()
|
||||||
|
val y = bar()
|
||||||
|
|
||||||
|
var r = "$x$y"
|
||||||
|
if (r != "2342") return "fail: $r"
|
||||||
|
|
||||||
|
r = "$y$x"
|
||||||
|
if (r != "4223") return "fail: $r"
|
||||||
|
|
||||||
|
r = "$x$x"
|
||||||
|
if (r != "2323") return "fail: $r"
|
||||||
|
|
||||||
|
r = "$y$y"
|
||||||
|
if (r != "4242") return "fail: $r"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(): Any = 23
|
||||||
|
|
||||||
|
fun bar() = 42
|
||||||
Reference in New Issue
Block a user