From f52ff02168e6330deaa3cbcd1245e60dc191457a Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Wed, 5 Feb 2025 13:33:15 +0100 Subject: [PATCH] Revert "use thistype instead" This reverts commit 47a26a2dbce8e0bc6153afb6d24307f5b1b58b21. --- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 10 +++++----- compiler/src/dotty/tools/dotc/core/Types.scala | 7 +++++-- .../src/scala/quoted/runtime/impl/QuotesImpl.scala | 7 +------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index a7f41a71d7ce..86351428af9e 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -31,7 +31,7 @@ object TypeOps: /** The type `tp` as seen from prefix `pre` and owner `cls`. See the spec * for what this means. */ - final def asSeenFrom(tp: Type, pre: Type, cls: Symbol)(using Context): Type = { + final def asSeenFrom(tp: Type, pre: Type, cls: Symbol, approximateUnstablePrefixes: Boolean)(using Context): Type = { pre match { case pre: QualSkolemType => // When a selection has an unstable qualifier, the qualifier type gets @@ -42,7 +42,7 @@ object TypeOps: // compute the type as seen from the widened prefix, and in the rare // cases where this leads to an approximated type we recompute it with // the skolemized prefix. See the i6199* tests for usecases. - val widenedAsf = new AsSeenFromMap(pre.info, cls) + val widenedAsf = new AsSeenFromMap(pre.info, cls, approximateUnstablePrefixes) val ret = widenedAsf.apply(tp) if widenedAsf.approxCount == 0 then @@ -52,11 +52,11 @@ object TypeOps: case _ => } - new AsSeenFromMap(pre, cls).apply(tp) + new AsSeenFromMap(pre, cls, approximateUnstablePrefixes).apply(tp) } /** The TypeMap handling the asSeenFrom */ - class AsSeenFromMap(pre: Type, cls: Symbol)(using Context) extends ApproximatingTypeMap, IdempotentCaptRefMap { + class AsSeenFromMap(pre: Type, cls: Symbol, approximateUnstablePrefixes: Boolean)(using Context) extends ApproximatingTypeMap, IdempotentCaptRefMap { /** The number of range approximations in invariant or contravariant positions * performed by this TypeMap. @@ -81,7 +81,7 @@ object TypeOps: case pre: SuperType => toPrefix(pre.thistpe, cls, thiscls) case _ => if (thiscls.derivesFrom(cls) && pre.baseType(thiscls).exists) - if (variance <= 0 && !isLegalPrefix(pre)) + if (approximateUnstablePrefixes && variance <= 0 && !isLegalPrefix(pre)) approxCount += 1 range(defn.NothingType, pre) else pre diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 2fcf628dbc01..4356da226ede 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -1106,11 +1106,14 @@ object Types extends TypeUtils { /** This type seen as if it were the type of a member of prefix type `pre` * declared in class `cls`. + * + * @param approximateUnstablePrefixes - needed for mamberType method in quotes reflect API, + * where we want to approximate less */ - final def asSeenFrom(pre: Type, cls: Symbol)(using Context): Type = { + final def asSeenFrom(pre: Type, cls: Symbol, approximateUnstablePrefixes: Boolean = true)(using Context): Type = { record("asSeenFrom") if (!cls.membersNeedAsSeenFrom(pre)) this - else TypeOps.asSeenFrom(this, pre, cls) + else TypeOps.asSeenFrom(this, pre, cls, approximateUnstablePrefixes) } // ----- Subtype-related -------------------------------------------- diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index b8f7c9efd9a0..c5d59eb5f391 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -1826,12 +1826,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def termSymbol: Symbol = self.termSymbol def isSingleton: Boolean = self.isSingleton def memberType(member: Symbol): TypeRepr = - // we use thisType to avoid resolving otherwise unstable prefixes into Nothing - val classSymbol = self.classSymbol - member.info - .asSeenFrom(classSymbol.thisType, member.owner) - .substThis(classSymbol.asClass, self) // and we remove the previously added This(_) for compatibility - + member.info.asSeenFrom(self, member.owner, approximateUnstablePrefixes = false) def baseClasses: List[Symbol] = self.baseClasses def baseType(cls: Symbol): TypeRepr = self.baseType(cls) def derivesFrom(cls: Symbol): Boolean = self.derivesFrom(cls)