From 157ed43c74c72cf31db4da3889befd891bc65041 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sat, 9 Mar 2024 18:48:10 -0500 Subject: [PATCH] Fix undercompilation upon ctor change **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;"`. --- compiler/src/dotty/tools/dotc/sbt/package.scala | 2 +- sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala | 2 +- sbt-test/source-dependencies/constructors/A.scala | 2 ++ sbt-test/source-dependencies/constructors/B.scala | 2 ++ sbt-test/source-dependencies/constructors/changes/A2.scala | 2 ++ sbt-test/source-dependencies/constructors/changes/B2.scala | 2 ++ 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/sbt/package.scala b/compiler/src/dotty/tools/dotc/sbt/package.scala index 379a2e45ce40..7c24319005ed 100644 --- a/compiler/src/dotty/tools/dotc/sbt/package.scala +++ b/compiler/src/dotty/tools/dotc/sbt/package.scala @@ -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 = diff --git a/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala b/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala index 2b2b7d26c716..d6cc3ac6339d 100644 --- a/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala +++ b/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala @@ -306,7 +306,7 @@ class ExtractUsedNamesSpecification { // All classes extend Object "Object", // All classes have a default constructor called - "java.lang.Object;init;", + "Object;init;", // the return type of the default constructor is Unit "Unit" ) diff --git a/sbt-test/source-dependencies/constructors/A.scala b/sbt-test/source-dependencies/constructors/A.scala index b81025bada4d..0c5a5efa5b25 100644 --- a/sbt-test/source-dependencies/constructors/A.scala +++ b/sbt-test/source-dependencies/constructors/A.scala @@ -1 +1,3 @@ +package example + class A(a: Int) diff --git a/sbt-test/source-dependencies/constructors/B.scala b/sbt-test/source-dependencies/constructors/B.scala index e44b1d4c7852..b66f04320f13 100644 --- a/sbt-test/source-dependencies/constructors/B.scala +++ b/sbt-test/source-dependencies/constructors/B.scala @@ -1 +1,3 @@ +package example + class B { val y = new A(2) } diff --git a/sbt-test/source-dependencies/constructors/changes/A2.scala b/sbt-test/source-dependencies/constructors/changes/A2.scala index edd9e160e7bf..5f72892e6f26 100644 --- a/sbt-test/source-dependencies/constructors/changes/A2.scala +++ b/sbt-test/source-dependencies/constructors/changes/A2.scala @@ -1 +1,3 @@ +package example + class A(a: String) diff --git a/sbt-test/source-dependencies/constructors/changes/B2.scala b/sbt-test/source-dependencies/constructors/changes/B2.scala index 701f0514685f..7b1399a8ac49 100644 --- a/sbt-test/source-dependencies/constructors/changes/B2.scala +++ b/sbt-test/source-dependencies/constructors/changes/B2.scala @@ -1 +1,3 @@ +package example + class B { val y = new A("a") }