Skip to content

Commit

Permalink
Merge pull request #790 from mkurz/Template0-22-fix
Browse files Browse the repository at this point in the history
Keep `Template[0-22]` also for Scala 3 for <=22 params
  • Loading branch information
mkurz committed May 22, 2024
2 parents 370c5e9 + 4a03d84 commit b01ab72
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +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
def valueOrEmptyIfScala3Exceeding22Params(params: Int, value: => String): String =
if (emitScala3Sources && params > 22) "" else value
}

private[compiler] object ScalaCompat {
Expand Down Expand Up @@ -576,8 +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 :+ """)""" :+ scalaCompat
.valueOrEmptyIfScala3(s" with $templateType") :+ """ {
""" :+ classDeclaration :+ """ extends _root_.play.twirl.api.BaseScalaTemplate[""" :+ resultType :+ """,_root_.play.twirl.api.Format[""" :+ resultType :+ """]](""" :+ formatterType :+ """)""" :+
(if (templateType.nonEmpty) s" with $templateType" else "") :+ """ {
/*""" :+ root.comment.map(_.msg).getOrElse("") :+ """*/
def apply""" :+ Source(root.params.str, root.params.pos) :+ """:""" :+ resultType :+ """ = {
Expand Down Expand Up @@ -735,7 +735,8 @@ package """ :+ packageName :+ """
.mkString
)

val templateType = sc.valueOrEmptyIfScala3(
val templateType = sc.valueOrEmptyIfScala3Exceeding22Params(
params.flatten.size,
"_root_.play.twirl.api.Template%s[%s%s]".format(
params.flatten.size,
params.flatten
Expand Down

0 comments on commit b01ab72

Please sign in to comment.