Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep Template[0-22] also for Scala 3 for <=22 params #790

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading