-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #12919: case class companion is never a singleton mirror
- Loading branch information
1 parent
9ed0762
commit f1163df
Showing
3 changed files
with
22 additions
and
2 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
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,20 @@ | ||
case class Normal(value: String) | ||
object Normal | ||
|
||
case class ClassWithCaseCompanion(value: String) | ||
case object ClassWithCaseCompanion | ||
|
||
def instantiate[T](product: Product)(implicit mirror: scala.deriving.Mirror.ProductOf[T]) = | ||
mirror.fromProduct(product) | ||
|
||
@main def Test: Unit = { | ||
assert(instantiate[Normal](Tuple1("a")) == Normal("a")) // works as expected | ||
|
||
assert(instantiate[ClassWithCaseCompanion.type](EmptyTuple) == ClassWithCaseCompanion) // works as expected | ||
|
||
val c = instantiate[ClassWithCaseCompanion](Tuple1("b")) // throws java.lang.ClassCastException: class ClassWithCaseCompanion$ cannot be cast to class ClassWithCaseCompanion | ||
assert(c == ClassWithCaseCompanion("b")) // desired behaviour | ||
|
||
val d = instantiate[ClassWithCaseCompanion.type](EmptyTuple) | ||
assert(d == ClassWithCaseCompanion) | ||
} |