Skip to content

Commit 5af00fd

Browse files
fix defaultArgument body synthesis: assign type Any to all cases, so match tree does not try to find the lub
1 parent 8ac6c6a commit 5af00fd

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,10 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
564564
val getterDenot = companionTree.tpe.member(getterName)
565565
companionTree.select(TermRef(companionTree.tpe, getterName, getterDenot))
566566

567-
val withDefaultCases =
568-
for (acc, idx) <- caseClass.caseAccessors.zipWithIndex if acc.is(HasDefault)
569-
yield CaseDef(Literal(Constant(idx)), EmptyTree, defaultArgumentGetter(idx))
567+
val withDefaultCases = for
568+
(acc, idx) <- caseClass.caseAccessors.zipWithIndex if acc.is(HasDefault)
569+
body = Typed(defaultArgumentGetter(idx), TypeTree(defn.AnyType)) // so match tree does try to find union of case types
570+
yield CaseDef(Literal(Constant(idx)), EmptyTree, body)
570571

571572
val withoutDefaultCase =
572573
val stringIndex = Apply(Select(index, nme.toString_), Nil)

tests/run/mirror-defaultArgument.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,8 @@ object Test extends App:
4545
val m5 = summon[Mirror.Of[outer.Inner]]
4646
assert(m5.defaultArgument(1) == 3 + 1)
4747
outer.localTest(9d)
48+
49+
50+
// new defaultArgument match tree should be able to unify different default value types
51+
case class Foo[T](x: Int = 0, y: String = "hi")
52+

0 commit comments

Comments
 (0)