Skip to content

Commit

Permalink
Merge pull request #748 from playframework/mergify/bp/1.6.x/pr-747
Browse files Browse the repository at this point in the history
[1.6.x] Support >22 args in Scala 3 (backport #747) by @mkurz
  • Loading branch information
mergify[bot] authored Mar 12, 2024
2 parents e978b93 + d3af099 commit 40a2291
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
25 changes: 15 additions & 10 deletions compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 :+ """ = {
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@****************************************************************************************************************************************************
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com> *
****************************************************************************************************************************************************@

@(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

0 comments on commit 40a2291

Please sign in to comment.