Skip to content

Commit 009bb33

Browse files
authored
Use NamedType#stableInRunSymbol more (#18108)
2 parents 69081e6 + 5d3c055 commit 009bb33

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,14 @@ object Types {
23242324
case _ => if (denotationIsCurrent) lastDenotation.nn.symbol else NoSymbol
23252325
}
23262326

2327+
/** Like `currentSymbol`, but force the denotation if the symbol isn't valid.
2328+
* Compared to `stableInRunSymbol`, this doesn't force the denotation for non-symbolic named types,
2329+
* because currentSymbol returns NoSymbol, which is `Permanent`, so always "isValidInCurrentRun".
2330+
* Forcing the denotation breaks tests/run/enrich-gentraversable.scala. */
2331+
private def currentValidSymbol(using Context): Symbol =
2332+
val sym = currentSymbol
2333+
if sym.isValidInCurrentRun then sym else denot.symbol
2334+
23272335
/** Retrieves currently valid symbol without necessarily updating denotation.
23282336
* Assumes that symbols do not change between periods in the same run.
23292337
* Used to get the class underlying a ThisType.
@@ -2677,10 +2685,7 @@ object Types {
26772685
else {
26782686
if (isType) {
26792687
val res =
2680-
val sym =
2681-
if (currentSymbol.isValidInCurrentRun) currentSymbol
2682-
else computeSymbol
2683-
if (sym.isAllOf(ClassTypeParam)) argForParam(prefix)
2688+
if (currentValidSymbol.isAllOf(ClassTypeParam)) argForParam(prefix)
26842689
else prefix.lookupRefined(name)
26852690
if (res.exists) return res
26862691
if (Config.splitProjections)
@@ -2754,9 +2759,7 @@ object Types {
27542759
/** A reference like this one, but with the given prefix. */
27552760
final def withPrefix(prefix: Type)(using Context): Type = {
27562761
def reload(): NamedType = {
2757-
val sym =
2758-
if lastSymbol.nn.isValidInCurrentRun then lastSymbol.nn
2759-
else computeSymbol
2762+
val sym = stableInRunSymbol
27602763
val allowPrivate = !sym.exists || sym.is(Private)
27612764
var d = memberDenot(prefix, name, allowPrivate)
27622765
if (d.isOverloaded && sym.exists)

0 commit comments

Comments
 (0)