-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mismatch between apply methods and initializers
When a case class is defined with no companion, the companion is synthesized by the compiler and every object creation of that case class is proxied to the synthesized apply method of the newly synthesized companion. From this perspective, if we have a `case class A(x: Int)` and a use site `A(1)`, `ExtractUsedNames` will extract the name to the apply method in `A(1)` and mark it as used. However, this is wrong. When the user changes the signature of the case class, only the signature of the case class constructor changes and this change is not propagated to the apply signature (`ExtractAPI` traverses trees, and the synthesized module has no trees as it is added in namer). Therefore, when we compare changed names in the old and new API, Zinc concludes that only references to `A;<init>;` must be recompiled and since the use site that contained `A(1)` had no such reference, then it's ignored. To fix this problem, we protect ourselves from this point of indirection and extract the proper name of the case class constructor iff the companion case class is indeed synthesized by the compiler. Note that when the user defines `object A` alongside the definition of `A`, Zinc does the right thing. Note that this fixes sbt/sbt#4316 and also fixes issues with default parameters in case classes.
- Loading branch information
Showing
12 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
zinc/src/sbt-test/source-dependencies/case-classes-no-companion/A.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
case class A ( | ||
name: String | ||
) |
4 changes: 4 additions & 0 deletions
4
zinc/src/sbt-test/source-dependencies/case-classes-no-companion/UseSite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
object UseSite extends App { | ||
println("hello world") | ||
val y = A("5") | ||
} |
3 changes: 3 additions & 0 deletions
3
zinc/src/sbt-test/source-dependencies/case-classes-no-companion/changes/A.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
case class A( | ||
name: Int | ||
) |
4 changes: 4 additions & 0 deletions
4
zinc/src/sbt-test/source-dependencies/case-classes-no-companion/changes/A2.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
case class A( | ||
name: Int, | ||
ms: Long = 0L | ||
) |
4 changes: 4 additions & 0 deletions
4
zinc/src/sbt-test/source-dependencies/case-classes-no-companion/changes/A3.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
case class A( | ||
name: Int, | ||
ms: String = "" | ||
) |
4 changes: 4 additions & 0 deletions
4
zinc/src/sbt-test/source-dependencies/case-classes-no-companion/changes/A4.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
case class A( | ||
name: Int, | ||
ms: Char = 'c' | ||
) |
4 changes: 4 additions & 0 deletions
4
zinc/src/sbt-test/source-dependencies/case-classes-no-companion/changes/UseSite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
object UseSite extends App { | ||
println("hello world") | ||
val y = A(5) | ||
} |
4 changes: 4 additions & 0 deletions
4
zinc/src/sbt-test/source-dependencies/case-classes-no-companion/changes/UseSite2.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
object UseSite extends App { | ||
println("hello world") | ||
val y = A(5, "asdf") | ||
} |
2 changes: 2 additions & 0 deletions
2
zinc/src/sbt-test/source-dependencies/case-classes-no-companion/incOptions.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
apiDebug = true | ||
relationsDebug = true |
13 changes: 13 additions & 0 deletions
13
zinc/src/sbt-test/source-dependencies/case-classes-no-companion/test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
> compile | ||
$ copy-file changes/A.scala A.scala | ||
-> compile | ||
$ copy-file changes/UseSite.scala UseSite.scala | ||
> run | ||
$ copy-file changes/A2.scala A.scala | ||
> run | ||
$ copy-file changes/A3.scala A.scala | ||
> run | ||
$ copy-file changes/UseSite2.scala UseSite.scala | ||
> run | ||
$ copy-file changes/A4.scala A.scala | ||
-> compile |