-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Class constructor parameter undercompilation #19910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Relevant issues: Repro repo: |
Likely the relevant code is around here where Scala 3 compiler builds up the dependency graph: scala3/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala Lines 172 to 211 in a9bb881
And here's how you can see the AST after parser phase: $ mkdir /tmp/hello
$ scalac scalaHelloWorld/src/main/scala/example/*.scala -d /tmp/hello -Xprint:parser -Yplain-printer
[[syntax trees at end of parser]] // scalaHelloWorld/src/main/scala/example/Hello.scala
PackageDef(Ident(example), List(
ModuleDef(Hello,
Template(DefDef(<init>, List(), TypeTree(), Thicket(List())),
List(Ident(App)), ValDef(_, Thicket(List()), Thicket(List())), List(
ValDef(service, TypeTree(),
Apply(Select(New(Ident(MyService)), <init>), List(Literal("fssdfs")))),
Apply(Ident(println), List(Literal("Works!")))))
)
))
[[syntax trees at end of parser]] // scalaHelloWorld/src/main/scala/example/MyService.scala
PackageDef(Ident(example), List(
TypeDef(MyService,
Template(
DefDef(<init>, List(List(ValDef(str, Ident(String), Thicket(List())))),
TypeTree(), Thicket(List())),
List(), ValDef(_, Thicket(List()), Thicket(List())), List())
)
)) In particular |
Here's my PR for this - #19911 |
Fixes #19910 Fixes sbt/zinc#1334 ## Problem Scala 3 compiler registers special `zincMangledName` for constructors for the purpose of incremental compilation. Currently the `zincMangledName` contains the package name, which does not match the use site tracking, thereby causing undercompilation during incremental compilation after a ctor change, like adding a parameter. There is an existing scripted test, but coincidentally the test class does NOT include packages, so the test ends up passing. ## Solution 1. This PR reproduces the issue by adding package name to the test. 2. This also fixes the problem by changing the `zincMangedName` to `sym.owner.name ++ ";init;"`. ## Note about zincMangedName `zincMangedName` in general is a good idea, which adds the class name into otherwise common name `<init>`. By making the name more unique it prevents overcompilation when one of the ctors changes in a file.
Compiler version
3.3.1
Minimized code
compiles and runs fine.
But when you add a parameter to
MyService
constructor, it still compiles but fails at runtime withNoSuchMethodError
.Output
Expectation
Code fails to compile.
The text was updated successfully, but these errors were encountered: