Skip to content

Commit d932af9

Browse files
authored
Merge pull request #10925 from dotty-staging/fix-#10634
Invalidate member caches after completing classes in Namer
2 parents 301943c + d32fdac commit d932af9

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,11 @@ object SymDenotations {
16301630
myBaseTypeCachePeriod = Nowhere
16311631
}
16321632

1633-
def invalidateMemberCaches(sym: Symbol)(using Context): Unit =
1633+
def invalidateMemberCaches()(using Context): Unit =
1634+
myMemberCachePeriod = Nowhere
1635+
invalidateMemberNamesCache()
1636+
1637+
def invalidateMemberCachesFor(sym: Symbol)(using Context): Unit =
16341638
if myMemberCache != null then myMemberCache.remove(sym.name)
16351639
if !sym.flagsUNSAFE.is(Private) then
16361640
invalidateMemberNamesCache()
@@ -1831,7 +1835,7 @@ object SymDenotations {
18311835
/** Enter a symbol in given `scope` without potentially replacing the old copy. */
18321836
def enterNoReplace(sym: Symbol, scope: MutableScope)(using Context): Unit =
18331837
scope.enter(sym)
1834-
invalidateMemberCaches(sym)
1838+
invalidateMemberCachesFor(sym)
18351839

18361840
/** Replace symbol `prev` (if defined in current class) by symbol `replacement`.
18371841
* If `prev` is not defined in current class, do nothing.

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ class Namer { typer: Typer =>
12311231
if (isDerivedValueClass(cls)) cls.setFlag(Final)
12321232
cls.info = avoidPrivateLeaks(cls)
12331233
cls.baseClasses.foreach(_.invalidateBaseTypeCache()) // we might have looked before and found nothing
1234+
cls.invalidateMemberCaches() // we might have checked for a member when parents were not known yet.
12341235
cls.setNoInitsFlags(parentsKind(parents), untpd.bodyKind(rest))
12351236
val ctorStable =
12361237
if cls.is(Trait) then cls.is(NoInits)

tests/pos/i10634/AParser.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
case class Parser(ctx: Context) extends BasicSupport
2+

tests/pos/i10634/BasicSupport.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// BasicSupport.scala
2+
trait BasicSupport:
3+
self: Parser =>
4+
5+
object SymOps extends SymOps[ctx.type](ctx)
6+
export SymOps._
7+
8+
def parse(sym: ctx.Symbol): Int =
9+
sym.getVisibility()
10+

tests/pos/i10634/Context.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Context.scala
2+
trait Context:
3+
type Symbol
4+
5+
trait SymOps[C <: Context](val c: C):
6+
extension (sym: c.Symbol)
7+
def getVisibility(): Int = 0
8+

0 commit comments

Comments
 (0)