diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 0f8171fef881..1bd17d6c9778 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1630,7 +1630,11 @@ object SymDenotations { myBaseTypeCachePeriod = Nowhere } - def invalidateMemberCaches(sym: Symbol)(using Context): Unit = + def invalidateMemberCaches()(using Context): Unit = + myMemberCachePeriod = Nowhere + invalidateMemberNamesCache() + + def invalidateMemberCachesFor(sym: Symbol)(using Context): Unit = if myMemberCache != null then myMemberCache.remove(sym.name) if !sym.flagsUNSAFE.is(Private) then invalidateMemberNamesCache() @@ -1831,7 +1835,7 @@ object SymDenotations { /** Enter a symbol in given `scope` without potentially replacing the old copy. */ def enterNoReplace(sym: Symbol, scope: MutableScope)(using Context): Unit = scope.enter(sym) - invalidateMemberCaches(sym) + invalidateMemberCachesFor(sym) /** Replace symbol `prev` (if defined in current class) by symbol `replacement`. * If `prev` is not defined in current class, do nothing. diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index c40800862a31..a91882c099a1 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1231,6 +1231,7 @@ class Namer { typer: Typer => if (isDerivedValueClass(cls)) cls.setFlag(Final) cls.info = avoidPrivateLeaks(cls) cls.baseClasses.foreach(_.invalidateBaseTypeCache()) // we might have looked before and found nothing + cls.invalidateMemberCaches() // we might have checked for a member when parents were not known yet. cls.setNoInitsFlags(parentsKind(parents), untpd.bodyKind(rest)) val ctorStable = if cls.is(Trait) then cls.is(NoInits) diff --git a/tests/pos/i10634/AParser.scala b/tests/pos/i10634/AParser.scala new file mode 100644 index 000000000000..c41b115d6454 --- /dev/null +++ b/tests/pos/i10634/AParser.scala @@ -0,0 +1,2 @@ +case class Parser(ctx: Context) extends BasicSupport + diff --git a/tests/pos/i10634/BasicSupport.scala b/tests/pos/i10634/BasicSupport.scala new file mode 100644 index 000000000000..cf4ae7190ce4 --- /dev/null +++ b/tests/pos/i10634/BasicSupport.scala @@ -0,0 +1,10 @@ +// BasicSupport.scala +trait BasicSupport: + self: Parser => + + object SymOps extends SymOps[ctx.type](ctx) + export SymOps._ + + def parse(sym: ctx.Symbol): Int = + sym.getVisibility() + diff --git a/tests/pos/i10634/Context.scala b/tests/pos/i10634/Context.scala new file mode 100644 index 000000000000..0e22fd29d17d --- /dev/null +++ b/tests/pos/i10634/Context.scala @@ -0,0 +1,8 @@ +// Context.scala +trait Context: + type Symbol + +trait SymOps[C <: Context](val c: C): + extension (sym: c.Symbol) + def getVisibility(): Int = 0 +