Skip to content

Invalidate member caches after completing classes in Namer #10925

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
Dec 29, 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
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/pos/i10634/AParser.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
case class Parser(ctx: Context) extends BasicSupport

10 changes: 10 additions & 0 deletions tests/pos/i10634/BasicSupport.scala
Original file line number Diff line number Diff line change
@@ -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()

8 changes: 8 additions & 0 deletions tests/pos/i10634/Context.scala
Original file line number Diff line number Diff line change
@@ -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