diff --git a/compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala b/compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala index c9c3969e..20f46d3d 100644 --- a/compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala +++ b/compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala @@ -166,6 +166,8 @@ object TwirlCompiler { private[compiler] class ScalaCompat(emitScala3Sources: Boolean) { val varargSplicesSyntax: String = if (emitScala3Sources) "*" else ": _*" + def valueOrEmptyIfScala3(value: => String): String = + if (emitScala3Sources) "" else value } private[compiler] object ScalaCompat { @@ -574,7 +576,8 @@ class """ :+ name :+ " " :+ constructorAnnotations :+ " " :+ Source(constructor. package """ :+ packageName :+ """ """ :+ imports :+ """ -""" :+ classDeclaration :+ """ extends _root_.play.twirl.api.BaseScalaTemplate[""" :+ resultType :+ """,_root_.play.twirl.api.Format[""" :+ resultType :+ """]](""" :+ formatterType :+ """) with """ :+ templateType :+ """ { +""" :+ classDeclaration :+ """ extends _root_.play.twirl.api.BaseScalaTemplate[""" :+ resultType :+ """,_root_.play.twirl.api.Format[""" :+ resultType :+ """]](""" :+ formatterType :+ """)""" :+ scalaCompat + .valueOrEmptyIfScala3(s" with $templateType") :+ """ { /*""" :+ root.comment.map(_.msg).getOrElse("") :+ """*/ def apply""" :+ Source(root.params.str, root.params.pos) :+ """:""" :+ resultType :+ """ = { @@ -732,15 +735,17 @@ package """ :+ packageName :+ """ .mkString ) - val templateType = "_root_.play.twirl.api.Template%s[%s%s]".format( - params.flatten.size, - params.flatten - .map { - case ByNameParam(_, paramType) => paramType - case p => filterType(p) - } - .mkString(","), - (if (params.flatten.isEmpty) "" else ",") + returnType + val templateType = sc.valueOrEmptyIfScala3( + "_root_.play.twirl.api.Template%s[%s%s]".format( + params.flatten.size, + params.flatten + .map { + case ByNameParam(_, paramType) => paramType + case p => filterType(p) + } + .mkString(","), + (if (params.flatten.isEmpty) "" else ",") + returnType + ) ) val f = "def f:%s = %s => apply%s".format( diff --git a/sbt-twirl/src/sbt-test/twirl/compile-scala3/src/test/scala/test/Test.scala b/sbt-twirl/src/sbt-test/twirl/compile-scala3/src/test/scala/test/Test.scala index d9db0c9f..b301587b 100644 --- a/sbt-twirl/src/sbt-test/twirl/compile-scala3/src/test/scala/test/Test.scala +++ b/sbt-twirl/src/sbt-test/twirl/compile-scala3/src/test/scala/test/Test.scala @@ -10,4 +10,10 @@ object Test extends App { test(a.b.html.c.render("world"), "Hello, world.\n") test(html.template.render("42"), "Answer: 42\n") + + test( + html.manyargstemplate.render( + "1", "2", "3", "5", "4", "7", "6", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26"), + "26 args: 1 2 3 5 4 7 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\n" + ) } diff --git a/sbt-twirl/src/sbt-test/twirl/compile-scala3/src/test/twirl/test/manyargstemplate.scala.html b/sbt-twirl/src/sbt-test/twirl/compile-scala3/src/test/twirl/test/manyargstemplate.scala.html new file mode 100644 index 00000000..58ed92ea --- /dev/null +++ b/sbt-twirl/src/sbt-test/twirl/compile-scala3/src/test/twirl/test/manyargstemplate.scala.html @@ -0,0 +1,6 @@ +@**************************************************************************************************************************************************** + * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. * + ****************************************************************************************************************************************************@ + +@(a: String, b: String, c: String, d: String, e: String, f: String, g: String, h: String, i: String, j: String, k: String, l: String, m: String, n: String, o: String, p: String, q: String, r: String, s: String, t: String, u: String, v: String, w: String, x: String, y: String, z: String) +26 args: @a @b @c @d @e @f @g @h @i @j @k @l @m @n @o @p @q @r @s @t @u @v @w @x @y @z