don't crash when appending an array to StringBuilder

This commit is contained in:
Dmitry Jemerov
2011-07-19 23:37:52 +02:00
parent 3dd73b47ec
commit a99bad7e47
2 changed files with 9 additions and 1 deletions
@@ -1316,7 +1316,7 @@ public class ExpressionCodegen extends JetVisitor {
}
Type exprType = expressionType(expr);
gen(expr, exprType);
invokeAppendMethod(exprType);
invokeAppendMethod(exprType.getSort() == Type.ARRAY ? JetTypeMapper.TYPE_OBJECT : exprType);
}
public void invokeAppendMethod(Type exprType) {
@@ -481,4 +481,12 @@ public class NamespaceGenTest extends CodegenTestCase {
final Method main = generateFunction();
assertEquals(false, ((Boolean) main.invoke(null, true)).booleanValue());
}
public void testAppendArrayToString() throws Exception {
loadText("fun foo(a: String, b: Array<String>) = a + b");
final Method main = generateFunction();
final String[] args = new String[] { "foo", "bar" };
//noinspection ImplicitArrayToString
assertEquals("s" + args.toString(), main.invoke(null, "s", args));
}
}