twirl icon indicating copy to clipboard operation
twirl copied to clipboard

`Implicit parameters should be provided with a using clause` warning since Scala 3.7

Open xuwei-k opened this issue 1 year ago • 5 comments

reproduce code

build.sbt

enablePlugins(SbtTwirl)

scalaVersion := "3.7.0-RC1-bin-20250215-43f8cdb-NIGHTLY"

project/build.properties

sbt.version=1.10.7

project/plugins.sbt

addSbtPlugin("org.playframework.twirl" % "sbt-twirl" % "2.1.0-M2")

src/main/twirl/example.scala.html

@(x: Int)(implicit y: Int)

<p>hello</p>

problem

sbt compile

/src/main/twirl/example.scala.html:3:13: Implicit parameters should be provided with a `using` clause.
[warn] This code can be rewritten automatically under -rewrite -source 3.7-migration.
[warn] To disable the warning, please use the following option: 
[warn]   "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
[warn] <p>hello</p>
[warn]             ^
[warn] one warning found

generated code

  /**/
  def apply/*1.2*/(x: Int)(implicit y: Int):play.twirl.api.HtmlFormat.Appendable = {
    _display_ {
      {


Seq[Any](format.raw/*2.1*/("""
"""),format.raw/*3.1*/("""<p>hello</p>
"""))
      }
    }
  }

  def render(x:Int,y:Int): play.twirl.api.HtmlFormat.Appendable = apply(x)(y)

  def f:((Int) => (Int) => play.twirl.api.HtmlFormat.Appendable) = (x) => (y) => apply(x)(y)

  def ref: this.type = this

expect

<   def render(x:Int,y:Int): play.twirl.api.HtmlFormat.Appendable = apply(x)(y)
---
>   def render(x:Int,y:Int): play.twirl.api.HtmlFormat.Appendable = apply(x)(using y)
29c29
<   def f:((Int) => (Int) => play.twirl.api.HtmlFormat.Appendable) = (x) => (y) => apply(x)(y)
---
>   def f:((Int) => (Int) => play.twirl.api.HtmlFormat.Appendable) = (x) => (y) => apply(x)(using y)

note

  • https://github.com/scala/scala3/pull/22441

xuwei-k avatar Feb 17 '25 02:02 xuwei-k

Thanks for the report. We probably want to adjust the generated scala 3 code. PRs welcome 😉

mkurz avatar Feb 17 '25 11:02 mkurz

@ajafri2001 Regarding you comment here, are you still interested to work on this?

mkurz avatar May 22 '25 13:05 mkurz

@mkurz yes please!

ajafri2001 avatar May 22 '25 13:05 ajafri2001

Not sure how much experience you have in sbt/scala/twirl. Maybe try first to set up a reproducer project so you can generate a test *.template.scala file. Then you modify the twirl source code (the fun part ;) to make things work ;) First I think you should understand and play around how https://github.com/playframework/twirl/blob/main/parser/src/main/scala/play/twirl/parser/TwirlParser.scala and https://github.com/playframework/twirl/blob/main/compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala works.

I need to run out of office now, but can advice more later and/or tomorrow.

mkurz avatar May 22 '25 13:05 mkurz

@mkurz I'm not too experienced (I didn't know scala as a language even existed a couple months ago 😅). But I did manage to figure out how to locally test/inspect the generated wrapper code via sbt-twirl. here's the pr I managed to come up with 😅.

I need to run out of office now, but can advice more later and/or tomorrow.

tysm, I would definitely appreciate any help you can give.

ajafri2001 avatar May 22 '25 14:05 ajafri2001