diff --git a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala index b41a8b8f1648..1f707bcd17d9 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala @@ -2790,27 +2790,7 @@ class JSCodeGen()(using genCtx: Context) { args: List[Tree]): js.Tree = { implicit val pos = tree.span - val arg = args.head - - /* Primitive number types such as scala.Int have a - * def +(s: String): String - * method, which is why we have to box the lhs sometimes. - * Otherwise, both lhs and rhs are already reference types (Any or String) - * so boxing is not necessary (in particular, rhs is never a primitive). - */ - assert(!isPrimitiveValueType(receiver.tpe) || arg.tpe.isRef(defn.StringClass)) - assert(!isPrimitiveValueType(arg.tpe)) - - val genLhs = { - val genLhs0 = genExpr(receiver) - // Box the receiver if it is a primitive value - if (!isPrimitiveValueType(receiver.tpe)) genLhs0 - else makePrimitiveBox(genLhs0, receiver.tpe) - } - - val genRhs = genExpr(arg) - - js.BinaryOp(js.BinaryOp.String_+, genLhs, genRhs) + js.BinaryOp(js.BinaryOp.String_+, genExpr(receiver), genExpr(args.head)) } /** Gen JS code for a call to Any.## */ diff --git a/tests/sjs-junit/test/org/scalajs/testsuite/compiler/RegressionTestScala3.scala b/tests/sjs-junit/test/org/scalajs/testsuite/compiler/RegressionTestScala3.scala index 1399763297ba..90d7df3ab281 100644 --- a/tests/sjs-junit/test/org/scalajs/testsuite/compiler/RegressionTestScala3.scala +++ b/tests/sjs-junit/test/org/scalajs/testsuite/compiler/RegressionTestScala3.scala @@ -44,6 +44,14 @@ class RegressionTestScala3 { assertEquals(1, X_Issue13221.I.i) assertEquals(1, X_Issue13221.blah) } + + @Test def primitivePlusStringThatIsATermRefIssue13518(): Unit = { + def charPlusString(x: String): String = 'a' + x + assertEquals("abc", charPlusString("bc")) + + def intPlusString(x: String): String = 5 + x + assertEquals("5bc", intPlusString("bc")) + } } object RegressionTestScala3 {