Skip to content

Commit 04d5068

Browse files
authored
Merge pull request #8206 from dotty-staging/fix-8203
Fix #8203: handle intersection type in parent registration
2 parents 0e847de + 3c9f377 commit 04d5068

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -898,28 +898,25 @@ class Namer { typer: Typer =>
898898
def registerIfChild(denot: SymDenotation)(implicit ctx: Context): Unit = {
899899
val sym = denot.symbol
900900

901-
def register(child: Symbol, parent: Type) = {
902-
val cls = parent.classSymbol
903-
if (cls.is(Sealed))
904-
if ((child.isInaccessibleChildOf(cls) || child.isAnonymousClass) && !sym.hasAnonymousChild)
905-
addChild(cls, cls)
906-
else if (!cls.is(ChildrenQueried))
907-
addChild(cls, child)
901+
def register(child: Symbol, parentCls: ClassSymbol) = {
902+
if (parentCls.is(Sealed))
903+
if ((child.isInaccessibleChildOf(parentCls) || child.isAnonymousClass) && !sym.hasAnonymousChild)
904+
addChild(parentCls, parentCls)
905+
else if (!parentCls.is(ChildrenQueried))
906+
addChild(parentCls, child)
908907
else
909-
ctx.error(em"""children of $cls were already queried before $sym was discovered.
910-
|As a remedy, you could move $sym on the same nesting level as $cls.""",
908+
ctx.error(em"""children of $parentCls were already queried before $sym was discovered.
909+
|As a remedy, you could move $sym on the same nesting level as $parentCls.""",
911910
child.sourcePos)
912911
}
913912

914-
if (denot.isClass && !sym.isEnumAnonymClass && !sym.isRefinementClass)
915-
denot.asClass.classParents.foreach { parent =>
916-
val child = if (denot.is(Module)) denot.sourceModule else denot.symbol
917-
register(child, parent)
918-
}
919-
else if (denot.is(CaseVal, butNot = Method | Module)) {
913+
if denot.isClass && !sym.isEnumAnonymClass && !sym.isRefinementClass then
914+
val child = if (denot.is(Module)) denot.sourceModule else denot.symbol
915+
denot.asClass.classParents.foreach { parent => register(child, parent.classSymbol.asClass) }
916+
else if denot.is(CaseVal, butNot = Method | Module) then
920917
assert(denot.is(Enum), denot)
921-
register(denot.symbol, denot.info)
922-
}
918+
denot.info.classSymbols.foreach { parent => register(denot.symbol, parent) }
919+
end if
923920
}
924921

925922
/** Intentionally left without `implicit ctx` parameter. We need

tests/patmat/i8203.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
sealed trait Pretty { self: Color => }
2+
sealed trait Dull { self: Color => }
3+
enum Color {
4+
case Pink extends Color with Pretty
5+
case Red extends Color with Dull
6+
}
7+
8+
def describe(c: Color) = c match {
9+
case Color.Pink => "Amazing!"
10+
case Color.Red => "Yawn..."
11+
}
12+
13+
def describe2(c: Pretty) = c match {
14+
case Color.Pink => "Amazing!"
15+
}
16+
17+
def describe3(c: Dull) = c match {
18+
case Color.Red => "Yawn..."
19+
}

0 commit comments

Comments
 (0)