Compiler version
3.1.1
Minimized code
project/plugins.sbt
addSbtPlugin("com.typesafe.play" % "sbt-twirl" % "1.6.0-M1")
build.sbt
enablePlugins(SbtTwirl)
scalaVersion := "3.1.1"
crossScalaVersions := Seq("2.13.8", "3.1.1")
libraryDependencies := libraryDependencies.value.map {
case module if module.name == "twirl-api" =>
module.cross(CrossVersion.for3Use2_13)
case module => module
}
src/main/twirl/error.scala.html
Output
toshi@/Users/toshi/tmp/twirl-example% sbt ++2.13.8 compile
...
[info] compiling 1 Scala source to /Users/toshi/tmp/twirl-example/target/scala-2.13/classes ...
[error] /Users/toshi/tmp/twirl-example/src/main/twirl/error.scala.html:1:12: not found: value world
[error] <h1>Hello @world</h1>
[error] ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 2 s, completed 2022/03/15 22:08:00
toshi@/Users/toshi/tmp/twirl-example% sbt ++3.1.1 compile
...
[info] compiling 1 Scala source to /Users/toshi/tmp/twirl-example/target/scala-3.1.1/classes ...
[error] -- [E006] Not Found Error: /Users/toshi/tmp/twirl-example/target/scala-3.1.1/twirl/main/html/error.template.scala:19:63
[error] 19 |Seq[Any](format.raw/*1.1*/("""<h1>Hello """),_display_(/*1.12*/world),format.raw/*1.17*/("""</h1>
[error] | ^^^^^
[error] | Not found: world
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 4 s, completed 2022/03/15 22:08:15
Expectation
When we write a template (.scala.html) for playframework/twirl, The template will be converted to a .scala file and compiled as a Scala object. If errors are found, Twirl shows them as template errors using sourcePositionMappers of sbt.
https://github.com/playframework/twirl/blob/2c064e741ff8771c68e6397518fc05cb16d61c67/sbt-twirl/src/main/scala/play/twirl/sbt/SbtTwirl.scala#L79
This works with Scala2 but doesn't work with Scala3. We see error messages directly from Dotty in Scala3.
I think this is because DelegatingReporter of Dotty passes a rendered parameter to xsbti.Reporter.
https://github.com/lampepfl/dotty/blob/d2ebd75a2e63e3dd885e7bad94472931d0bae296/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java#L47
If the rendered parameter is passed, sbt will display the contents of the rendered parameter, and information other than the rendered parameter is ignored. The error information translated by sourcePositionMappers in sbt's ManagedLoggedReporter will also not be displayed.
If I modify the DelegatingReporter so that the rendered parameter is not passed to sbt, it is possible to display the same error message as when compiling with Scala2. However, the message stored in the rendered parameter is from Dotty and contains more detailed error messages, so I feel a bit uncomfortable making it completely invisible. What do you think?
Compiler version
3.1.1
Minimized code
project/plugins.sbt
build.sbt
src/main/twirl/error.scala.html
Output
Expectation
When we write a template (.scala.html) for playframework/twirl, The template will be converted to a .scala file and compiled as a Scala object. If errors are found, Twirl shows them as template errors using
sourcePositionMappersof sbt.https://github.com/playframework/twirl/blob/2c064e741ff8771c68e6397518fc05cb16d61c67/sbt-twirl/src/main/scala/play/twirl/sbt/SbtTwirl.scala#L79
This works with Scala2 but doesn't work with Scala3. We see error messages directly from Dotty in Scala3.
I think this is because
DelegatingReporterof Dotty passes arenderedparameter toxsbti.Reporter.https://github.com/lampepfl/dotty/blob/d2ebd75a2e63e3dd885e7bad94472931d0bae296/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java#L47
If the
renderedparameter is passed, sbt will display the contents of therenderedparameter, and information other than therenderedparameter is ignored. The error information translated bysourcePositionMappersin sbt'sManagedLoggedReporterwill also not be displayed.If I modify the
DelegatingReporterso that therenderedparameter is not passed to sbt, it is possible to display the same error message as when compiling with Scala2. However, the message stored in therenderedparameter is from Dotty and contains more detailed error messages, so I feel a bit uncomfortable making it completely invisible. What do you think?