diff --git a/classlib/src/main/java/org/teavm/classlib/impl/StringConcatFactorySubstitutor.java b/classlib/src/main/java/org/teavm/classlib/impl/StringConcatFactorySubstitutor.java index f79929ede..904e95cae 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/StringConcatFactorySubstitutor.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/StringConcatFactorySubstitutor.java @@ -23,6 +23,7 @@ import org.teavm.model.RuntimeConstant; import org.teavm.model.ValueType; import org.teavm.model.emit.ProgramEmitter; import org.teavm.model.emit.ValueEmitter; +import org.teavm.model.instructions.IntegerSubtype; public class StringConcatFactorySubstitutor implements BootstrapMethodSubstitutor { private ReferenceCache referenceCache = new ReferenceCache(); @@ -99,7 +100,20 @@ public class StringConcatFactorySubstitutor implements BootstrapMethodSubstituto } private ValueEmitter appendArgument(ValueEmitter sb, ValueType type, ValueEmitter argument) { - if (!(type instanceof ValueType.Primitive)) { + if (type instanceof ValueType.Primitive) { + switch (((ValueType.Primitive) type).getKind()) { + case BYTE: + argument = argument.castToInteger(IntegerSubtype.BYTE); + type = ValueType.INTEGER; + break; + case SHORT: + argument = argument.castToInteger(IntegerSubtype.SHORT); + type = ValueType.INTEGER; + break; + default: + break; + } + } else { type = ValueType.object("java.lang.Object"); } MethodReference method = referenceCache.getCached(new MethodReference(STRING_BUILDER, "append", type, diff --git a/tests/src/test/java/org/teavm/vm/VMTest.java b/tests/src/test/java/org/teavm/vm/VMTest.java index 434d85a2b..b55f287e3 100644 --- a/tests/src/test/java/org/teavm/vm/VMTest.java +++ b/tests/src/test/java/org/teavm/vm/VMTest.java @@ -181,12 +181,22 @@ public class VMTest { public void stringConcat() { assertEquals("(23)", surroundWithParentheses(23)); assertEquals("(42)", surroundWithParentheses(42)); + assertEquals("(17)", surroundWithParentheses((byte) 17)); + assertEquals("(19)", surroundWithParentheses((short) 19)); } private String surroundWithParentheses(int value) { return "(" + value + ")"; } + private String surroundWithParentheses(byte value) { + return "(" + value + ")"; + } + + private String surroundWithParentheses(short value) { + return "(" + value + ")"; + } + @Test public void variableReadInCatchBlock() { int n = foo();