Skip to content

Commit

Permalink
Fix undercompilation upon ctor change
Browse files Browse the repository at this point in the history
**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**
This PR reproduces the issue by adding package name to the test.
This also fixes the problem by changing the `zincMangedName`
to `sym.owner.name ++ ";init;"`.
  • Loading branch information
eed3si9n committed Mar 10, 2024
1 parent a9bb881 commit 157ed43
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/sbt/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inline val InlineParamHash = 1997 // 302nd prime
extension (sym: Symbol)

def constructorName(using Context) =
sym.owner.fullName ++ ";init;"
sym.owner.name ++ ";init;"

/** Mangle a JVM symbol name in a format better suited for internal uses by sbt. */
def zincMangledName(using Context): Name =
Expand Down
2 changes: 1 addition & 1 deletion sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class ExtractUsedNamesSpecification {
// All classes extend Object
"Object",
// All classes have a default constructor called <init>
"java.lang.Object;init;",
"Object;init;",
// the return type of the default constructor is Unit
"Unit"
)
Expand Down
2 changes: 2 additions & 0 deletions sbt-test/source-dependencies/constructors/A.scala
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package example

class A(a: Int)
2 changes: 2 additions & 0 deletions sbt-test/source-dependencies/constructors/B.scala
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package example

class B { val y = new A(2) }
2 changes: 2 additions & 0 deletions sbt-test/source-dependencies/constructors/changes/A2.scala
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package example

class A(a: String)
2 changes: 2 additions & 0 deletions sbt-test/source-dependencies/constructors/changes/B2.scala
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package example

class B { val y = new A("a") }

0 comments on commit 157ed43

Please sign in to comment.