Add toString call when interpolating strings
This commit is contained in:
@@ -48,4 +48,14 @@ public final class StringTest extends AbstractExpressionTest {
|
|||||||
public void testObjectToStringCallInTemplate() throws Exception {
|
public void testObjectToStringCallInTemplate() throws Exception {
|
||||||
fooBoxTest();
|
fooBoxTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testStringNotEqualToNumber() throws Exception {
|
||||||
|
fooBoxTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testKt2227() throws Exception {
|
||||||
|
fooBoxTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -17,6 +17,8 @@
|
|||||||
package org.jetbrains.k2js.translate.expression;
|
package org.jetbrains.k2js.translate.expression;
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
|
import com.google.dart.compiler.util.AstUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
@@ -24,6 +26,7 @@ import org.jetbrains.k2js.translate.context.TranslationContext;
|
|||||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||||
import org.jetbrains.k2js.translate.general.Translation;
|
import org.jetbrains.k2js.translate.general.Translation;
|
||||||
|
|
||||||
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.setQualifier;
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.sum;
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.sum;
|
||||||
|
|
||||||
|
|
||||||
@@ -77,7 +80,10 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
|||||||
JetExpression entryExpression = entry.getExpression();
|
JetExpression entryExpression = entry.getExpression();
|
||||||
assert entryExpression != null :
|
assert entryExpression != null :
|
||||||
"JetStringTemplateEntryWithExpression must have not null entry expression.";
|
"JetStringTemplateEntryWithExpression must have not null entry expression.";
|
||||||
append(Translation.translateAsExpression(entryExpression, context()));
|
JsExpression translatedExpression = Translation.translateAsExpression(entryExpression, context());
|
||||||
|
JsNameRef toString = AstUtil.newQualifiedNameRef("toString");
|
||||||
|
setQualifier(toString, translatedExpression);
|
||||||
|
append(AstUtil.newInvocation(toString));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
fun box(): Boolean {
|
||||||
|
if ("${3}" != "3") return false
|
||||||
|
return "${3}" == "3"
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
|
||||||
|
fun box(): Boolean {
|
||||||
|
val t1: Any = "3"
|
||||||
|
val t2: Any = 3
|
||||||
|
val t3: Any = "4"
|
||||||
|
val t4: Any = 4
|
||||||
|
if (t3 == t4) return false
|
||||||
|
return t1 != t2
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user