Skip to content

Commit ea6bca1

Browse files
committed
fix(patmat): Use childPrefix to resolve path-dependent sealed children
1 parent e9cb3bb commit ea6bca1

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,22 @@ object TypeOps:
748748
//
749749
if (child.name == tpnme.LOCAL_CHILD) return child.typeRef
750750

751-
val childTp = if (child.isTerm) child.termRef else child.typeRef
751+
val childTp = {
752+
val parentSym = parent.typeSymbol
753+
val parentPre = parent.normalizedPrefix
754+
val defaultRef = if (child.isTerm) child.termRef else child.typeRef
755+
756+
if (parentSym.isClass && parentPre.isInstanceOf[TermRef]) {
757+
val newPrefix = childPrefix(parentPre, parentSym, child)
758+
if (newPrefix.exists)
759+
if (child.isTerm) TermRef(newPrefix, child.asTerm)
760+
else TypeRef(newPrefix, child.asType)
761+
else
762+
defaultRef
763+
}
764+
else
765+
defaultRef
766+
}
752767

753768
inContext(ctx.fresh.setExploreTyperState().setFreshGADTBounds.addMode(Mode.GadtConstraintInference)) {
754769
instantiateToSubType(childTp, parent, mixins).dealias

tests/warn/i23369.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Module {
2+
type BarTy
3+
sealed trait Adt[A]
4+
case class Foo() extends Adt[String]
5+
case class Bar[A <: BarTy](x: BarTy) extends Adt[A]
6+
}
7+
8+
object Basic extends Module {
9+
type BarTy = String
10+
}
11+
12+
def test(a: Basic.Adt[String]) = {
13+
a match { // warn: match may not be exhaustive
14+
case Basic.Foo() =>
15+
}
16+
}

0 commit comments

Comments
 (0)