Skip to content

Use NamedType#stableInRunSymbol more #18108

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 2 commits into from
Jul 3, 2023
Merged
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
17 changes: 10 additions & 7 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,14 @@ object Types {
case _ => if (denotationIsCurrent) lastDenotation.nn.symbol else NoSymbol
}

/** Like `currentSymbol`, but force the denotation if the symbol isn't valid.
* Compared to `stableInRunSymbol`, this doesn't force the denotation for non-symbolic named types,
* because currentSymbol returns NoSymbol, which is `Permanent`, so always "isValidInCurrentRun".
* Forcing the denotation breaks tests/run/enrich-gentraversable.scala. */
private def currentValidSymbol(using Context): Symbol =
val sym = currentSymbol
if sym.isValidInCurrentRun then sym else denot.symbol

/** Retrieves currently valid symbol without necessarily updating denotation.
* Assumes that symbols do not change between periods in the same run.
* Used to get the class underlying a ThisType.
Expand Down Expand Up @@ -2677,10 +2685,7 @@ object Types {
else {
if (isType) {
val res =
val sym =
if (currentSymbol.isValidInCurrentRun) currentSymbol
else computeSymbol
if (sym.isAllOf(ClassTypeParam)) argForParam(prefix)
if (currentValidSymbol.isAllOf(ClassTypeParam)) argForParam(prefix)
else prefix.lookupRefined(name)
if (res.exists) return res
if (Config.splitProjections)
Expand Down Expand Up @@ -2754,9 +2759,7 @@ object Types {
/** A reference like this one, but with the given prefix. */
final def withPrefix(prefix: Type)(using Context): Type = {
def reload(): NamedType = {
val sym =
if lastSymbol.nn.isValidInCurrentRun then lastSymbol.nn
else computeSymbol
val sym = stableInRunSymbol
val allowPrivate = !sym.exists || sym.is(Private)
var d = memberDenot(prefix, name, allowPrivate)
if (d.isOverloaded && sym.exists)
Expand Down