3

I am migrating to Scala 2.13.

args: (Symbol, String)* in a Play Twirl template gives me this warning:

Passing an explicit array value to a Scala varargs method is deprecated (since 2.13.0) and will result in a defensive copy; Use the more efficient non-copying ArraySeq.unsafeWrapArray or an explicit toIndexedSeq call

Here is the whole template:

@(action: play.api.mvc.Call, args: (Symbol, String)*)(body: => Html)
<form  method="@action.method"
  @toHtmlArgs(args.toMap)>
  @body
</form>

Here is how this function is called:

@helper.formRelative(action = ..., Symbol("id") -> "assignForm", Symbol("class") -> "ui form") { ..body.. }

As I use this in a lot of places, is there a way to resolve this without changing the signature?

I tried different things, like:

  • add toSeq: @toHtmlArgs(args.toSeq.toMap)
  • also with removing @toHtmlArgs(args.toMap) the warning showed up.
pme
  • 11,442
  • 2
  • 35
  • 62

1 Answers1

0

As suggested, use scala.collection.immutable.ArraySeq.unsafeWrapArray : pass this as args:

unsafeWrapArray(Array(Symbol("id") -> "assignForm", Symbol("class") -> "ui form")):_*
Saurav Sahu
  • 9,755
  • 5
  • 42
  • 64