pme
pme

Reputation: 14813

Scala 2.13: Passing an explicit array value to a Scala varargs method is deprecated

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:

Upvotes: 5

Views: 1189

Answers (1)

Saurav Sahu
Saurav Sahu

Reputation: 13994

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

unsafeWrapArray(Array(Symbol("id") -> "assignForm", Symbol("class") -> "ui form")):_*

Upvotes: 1

Related Questions