Skip to content

Commit

Permalink
Revert "use thistype instead"
Browse files Browse the repository at this point in the history
This reverts commit 47a26a2.
  • Loading branch information
jchyb committed Feb 5, 2025
1 parent 47a26a2 commit f52ff02
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------------------------
Expand Down
7 changes: 1 addition & 6 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f52ff02

Please sign in to comment.