Closed mrdziuban closed 1 year ago
nice catch. compared to Scala 2, I think Scala 3 compiler plugins in are in much less wide use, so I'm not too surprised that something quite basic like this is broken (but it's dismaying nonetheless, of course)
I'll take a quick look. At a glance, maybe the Run re-adds the plugin when the Context is built.
I took a look, and Scala 3 expects to instantiate phase objects per Run. The example incorrectly supplies the same phase object in init
, where init
allows a phase to optionally participate in the Run. It works correctly as:
override def init(opts: List[String]): List[PluginPhase] = List(ExamplePhase())
class ExamplePhase extends PluginPhase {
There is no trivial means to subvert this requirement (by overriding behavior).
Not closing in case there is documentation follow-up.
Oooh, very good to know, thank you @som-snytt! ~Feel free to close this if you'd like, or reuse it for documenting the behavior if you think it's worthwhile~ sorry I see you already said this 😄
@mrdziuban was your sample plugin code copied from some upstream source where the bug could be corrected?
I am the author of (closed source) Scala 3 compiler plugin and I see that my plugin has this bug, so I'm glad to learn of it, thanks.
I see no indication of the requirement in the Scaladoc of StandardPlugin
(or ResearchPlugin
). We should document it.
Yeah I maintain a couple open source plugins at work, I just updated both of them a bit ago
doc PR: #18394
Compiler version
3.3.0, also with the latest 3.3.1-RC4 and nightly 3.4.0-RC1-bin-20230809-c5adafc-NIGHTLY
Minimized code
https://github.com/mrdziuban/dotty-compiler-plugin-issue
After cloning that repo and running
sbt package
, you can reproduce the issue by runningscala
with the plugin:and then by evaluating two statements:
Output
When evaluating the second statement, the REPL crashes:
Expectation
The REPL should handle compiler plugins and not crash