[JS BE] Fix KT-26706: incorrect Long value in string templates
This commit is contained in:
+5
@@ -6306,6 +6306,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/number/kt2342.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26706.kt")
|
||||
public void testKt26706() throws Exception {
|
||||
runTest("js/js.translator/testData/box/number/kt26706.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("longArray.kt")
|
||||
public void testLongArray() throws Exception {
|
||||
runTest("js/js.translator/testData/box/number/longArray.kt");
|
||||
|
||||
+5
@@ -6306,6 +6306,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/number/kt2342.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26706.kt")
|
||||
public void testKt26706() throws Exception {
|
||||
runTest("js/js.translator/testData/box/number/kt26706.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("longArray.kt")
|
||||
public void testLongArray() throws Exception {
|
||||
runTest("js/js.translator/testData/box/number/longArray.kt");
|
||||
|
||||
+10
@@ -113,6 +113,16 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
||||
private boolean mustCallToString(@NotNull KotlinType type) {
|
||||
Name typeName = DescriptorUtilsKt.getNameIfStandardType(type);
|
||||
//TODO: this is a hacky optimization, should use some generic approach
|
||||
|
||||
// Long has valueOf method which will be called instead of toString and produce different result.
|
||||
if (KotlinBuiltIns.isAny(type) ||
|
||||
KotlinBuiltIns.isComparable(type) ||
|
||||
KotlinBuiltIns.isNumber(type) ||
|
||||
KotlinBuiltIns.isLong(type)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (typeName != null && NamePredicate.STRING.test(typeName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1229
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val x = "895065487315017728"
|
||||
if (" ${x.toLong()}" != " $x") return "FAIL 1"
|
||||
if (" ${x.toLong() as Comparable<Long>}" != " $x") return "FAIL 2"
|
||||
if (" ${x.toLong() as Number}" != " $x") return "FAIL 3"
|
||||
if (" ${x.toLong() as Any}" != " $x") return "FAIL 4"
|
||||
if (" ${x.toLong() as Long?}" != " $x") return "FAIL 5"
|
||||
if (" ${x.toLong() as Comparable<Long>?}" != " $x") return "FAIL 6"
|
||||
if (" ${x.toLong() as Number?}" != " $x") return "FAIL 7"
|
||||
if (" ${x.toLong() as Any?}" != " $x") return "FAIL 8"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user