Skip to content

Commit 5fb2299

Browse files
authored
Consider all parents when checking access to the children of a sum (#19083)
Fix #18918
2 parents 9aad151 + 5b2ec61 commit 5fb2299

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class SymUtils:
181181
else {
182182
val children = self.children
183183
val companionMirror = self.useCompanionAsSumMirror
184-
val ownerScope = if pre.isInstanceOf[SingletonType] then pre.classSymbol else NoSymbol
184+
val ownerScope = if pre.isInstanceOf[SingletonType] then pre.classSymbols else Nil
185185
def problem(child: Symbol) = {
186186

187187
def accessibleMessage(sym: Symbol): String =
@@ -191,8 +191,7 @@ class SymUtils:
191191
self.isContainedIn(sym) || sym.is(Module) && isVisibleToParent(sym.owner)
192192
def isVisibleToScope(sym: Symbol): Boolean =
193193
def isReachable: Boolean = ctx.owner.isContainedIn(sym)
194-
def isMemberOfPrefix: Boolean =
195-
ownerScope.exists && inherits(sym, ownerScope)
194+
def isMemberOfPrefix: Boolean = ownerScope.exists(inherits(sym, _))
196195
isReachable || isMemberOfPrefix || sym.is(Module) && isVisibleToScope(sym.owner)
197196
if !isVisibleToParent(sym) then i"to its parent $self"
198197
else if !companionMirror && !isVisibleToScope(sym) then i"to call site ${ctx.owner}"

tests/pos/i18918.scala

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
trait SuperTrait {
3+
sealed trait InnerTrait
4+
case class Foo() extends InnerTrait
5+
}
6+
7+
trait OtherTrait
8+
9+
trait TraitWithSelfType extends SuperTrait { this: OtherTrait =>
10+
summon[deriving.Mirror.Of[Foo]]
11+
summon[deriving.Mirror.Of[InnerTrait]]
12+
}
13+
14+
object Implementation extends TraitWithSelfType, OtherTrait {
15+
summon[deriving.Mirror.Of[Foo]]
16+
summon[deriving.Mirror.Of[InnerTrait]]
17+
}

0 commit comments

Comments
 (0)