From 4d4621532971ccacb74698641a2039fcf38a5db5 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Sun, 23 Jun 2024 19:44:05 +0200 Subject: [PATCH 1/2] Consider all parents when checking access to the children of a sum [Cherry-picked 7be702b27a26e0bbcd0efdc1694491e0220a5f0b][modified] --- .../dotty/tools/dotc/transform/SymUtils.scala | 5 ++--- tests/pos/i18918.scala | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i18918.scala diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index 3b5b8c77175e..facf81273db8 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -173,7 +173,7 @@ object SymUtils: else { val children = self.children val companionMirror = self.useCompanionAsSumMirror - val ownerScope = if pre.isInstanceOf[SingletonType] then pre.classSymbol else NoSymbol + val ownerScope = if pre.isInstanceOf[SingletonType] then pre.parentSymbols(_.isClass) else Nil def problem(child: Symbol) = { def accessibleMessage(sym: Symbol): String = @@ -183,8 +183,7 @@ object SymUtils: self.isContainedIn(sym) || sym.is(Module) && isVisibleToParent(sym.owner) def isVisibleToScope(sym: Symbol): Boolean = def isReachable: Boolean = ctx.owner.isContainedIn(sym) - def isMemberOfPrefix: Boolean = - ownerScope.exists && inherits(sym, ownerScope) + def isMemberOfPrefix: Boolean = ownerScope.exists(inherits(sym, _)) isReachable || isMemberOfPrefix || sym.is(Module) && isVisibleToScope(sym.owner) if !isVisibleToParent(sym) then i"to its parent $self" else if !companionMirror && !isVisibleToScope(sym) then i"to call site ${ctx.owner}" diff --git a/tests/pos/i18918.scala b/tests/pos/i18918.scala new file mode 100644 index 000000000000..0ec6f29b2b89 --- /dev/null +++ b/tests/pos/i18918.scala @@ -0,0 +1,17 @@ + +trait SuperTrait { + sealed trait InnerTrait + case class Foo() extends InnerTrait +} + +trait OtherTrait + +trait TraitWithSelfType extends SuperTrait { this: OtherTrait => + summon[deriving.Mirror.Of[Foo]] + summon[deriving.Mirror.Of[InnerTrait]] +} + +object Implementation extends TraitWithSelfType, OtherTrait { + summon[deriving.Mirror.Of[Foo]] + summon[deriving.Mirror.Of[InnerTrait]] +} From 93976e9e7455c451d34a182b0dbed20d19f5612f Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Sun, 23 Jun 2024 19:45:25 +0200 Subject: [PATCH 2/2] Use classSymbols method Co-authored-by: Jamie Thompson [Cherry-picked 5b2ec61938c4e6c5b29b0c883a463acd88eab6dd][modified] --- compiler/src/dotty/tools/dotc/transform/SymUtils.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index facf81273db8..0b52689adabf 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -173,7 +173,7 @@ object SymUtils: else { val children = self.children val companionMirror = self.useCompanionAsSumMirror - val ownerScope = if pre.isInstanceOf[SingletonType] then pre.parentSymbols(_.isClass) else Nil + val ownerScope = if pre.isInstanceOf[SingletonType] then pre.classSymbols else Nil def problem(child: Symbol) = { def accessibleMessage(sym: Symbol): String =