Add toString call when interpolating strings

This commit is contained in:
pTalanov
2012-06-15 17:26:45 +04:00
parent 1ba6470e8d
commit 3bb14ecd7f
4 changed files with 34 additions and 1 deletions
@@ -48,4 +48,14 @@ public final class StringTest extends AbstractExpressionTest {
public void testObjectToStringCallInTemplate() throws Exception {
fooBoxTest();
}
public void testStringNotEqualToNumber() throws Exception {
fooBoxTest();
}
public void testKt2227() throws Exception {
fooBoxTest();
}
}
@@ -17,6 +17,8 @@
package org.jetbrains.k2js.translate.expression;
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.Nullable;
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.Translation;
import static org.jetbrains.k2js.translate.utils.JsAstUtils.setQualifier;
import static org.jetbrains.k2js.translate.utils.JsAstUtils.sum;
@@ -77,7 +80,10 @@ public final class StringTemplateTranslator extends AbstractTranslator {
JetExpression entryExpression = entry.getExpression();
assert entryExpression != null :
"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
@@ -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
}