Skip to content

Fix #8203: handle intersection type in parent registration #8206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -901,28 +901,25 @@ class Namer { typer: Typer =>
def registerIfChild(denot: SymDenotation)(implicit ctx: Context): Unit = {
val sym = denot.symbol

def register(child: Symbol, parent: Type) = {
val cls = parent.classSymbol
if (cls.is(Sealed))
if ((child.isInaccessibleChildOf(cls) || child.isAnonymousClass) && !sym.hasAnonymousChild)
addChild(cls, cls)
else if (!cls.is(ChildrenQueried))
addChild(cls, child)
def register(child: Symbol, parentCls: ClassSymbol) = {
if (parentCls.is(Sealed))
if ((child.isInaccessibleChildOf(parentCls) || child.isAnonymousClass) && !sym.hasAnonymousChild)
addChild(parentCls, parentCls)
else if (!parentCls.is(ChildrenQueried))
addChild(parentCls, child)
else
ctx.error(em"""children of $cls were already queried before $sym was discovered.
|As a remedy, you could move $sym on the same nesting level as $cls.""",
ctx.error(em"""children of $parentCls were already queried before $sym was discovered.
|As a remedy, you could move $sym on the same nesting level as $parentCls.""",
child.sourcePos)
}

if (denot.isClass && !sym.isEnumAnonymClass && !sym.isRefinementClass)
denot.asClass.classParents.foreach { parent =>
val child = if (denot.is(Module)) denot.sourceModule else denot.symbol
register(child, parent)
}
else if (denot.is(CaseVal, butNot = Method | Module)) {
if denot.isClass && !sym.isEnumAnonymClass && !sym.isRefinementClass then
val child = if (denot.is(Module)) denot.sourceModule else denot.symbol
denot.asClass.classParents.foreach { parent => register(child, parent.classSymbol.asClass) }
else if denot.is(CaseVal, butNot = Method | Module) then
assert(denot.is(Enum), denot)
register(denot.symbol, denot.info)
}
denot.info.classSymbols.foreach { parent => register(denot.symbol, parent) }
end if
}

/** Intentionally left without `implicit ctx` parameter. We need
Expand Down
19 changes: 19 additions & 0 deletions tests/patmat/i8203.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
sealed trait Pretty { self: Color => }
sealed trait Dull { self: Color => }
enum Color {
case Pink extends Color with Pretty
case Red extends Color with Dull
}

def describe(c: Color) = c match {
case Color.Pink => "Amazing!"
case Color.Red => "Yawn..."
}

def describe2(c: Pretty) = c match {
case Color.Pink => "Amazing!"
}

def describe3(c: Dull) = c match {
case Color.Red => "Yawn..."
}