question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`sourcePositionMapper` of sbt doesn't work with `DelegatingReporter` of Dotty

See original GitHub issue

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

<h1>Hello @world</h1>

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?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
brbrown25commented, Mar 16, 2022

I don’t feel able to tackle this myself, but I do hope that a volunteer can be found, since it would help Play get onto Scala 3.

I’d be happy to assist anyone who wants to work on Zinc, if Zinc needs updates.

I’m always happy to learn new things and help out, maybe we can find sometime to collaborate together on this 😃

0reactions
eed3si9ncommented, Mar 15, 2022

I don’t feel able to tackle this myself, but I do hope that a volunteer can be found, since it would help Play get onto Scala 3.

I’d be happy to assist anyone who wants to work on Zinc, if Zinc needs updates.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The compiler interface should expose sourcePositionMappers ...
smarter mentioned this issue on Mar 15. sourcePositionMapper of sbt doesn't work with DelegatingReporter of Dotty lampepfl/dotty#14691. Open.
Read more >
Revisiting Dotty Diagnostics for tooling - Scala Contributors
I'd like to revisit some of the previous discussions and movement around the idea of “structured diagnostics” in Dotty.
Read more >
JetBrains/intellij-scala - Gitter
Hi! So I'm using dotty + EAP scala plugin. I'm having two consistent issues: 1.) optimize imports doesn't remove unused imports and 2.)...
Read more >
IntelliJ IDEA - Troubleshoot common Scala issues - JetBrains
Check the following answers on most common scala/sbt questions that can help you solve compiler, performance or code highlighting issues you might come ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found