Skip to content

Commit f52ff02

Browse files
committed
Revert "use thistype instead"
This reverts commit 47a26a2.
1 parent 47a26a2 commit f52ff02

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object TypeOps:
3131
/** The type `tp` as seen from prefix `pre` and owner `cls`. See the spec
3232
* for what this means.
3333
*/
34-
final def asSeenFrom(tp: Type, pre: Type, cls: Symbol)(using Context): Type = {
34+
final def asSeenFrom(tp: Type, pre: Type, cls: Symbol, approximateUnstablePrefixes: Boolean)(using Context): Type = {
3535
pre match {
3636
case pre: QualSkolemType =>
3737
// When a selection has an unstable qualifier, the qualifier type gets
@@ -42,7 +42,7 @@ object TypeOps:
4242
// compute the type as seen from the widened prefix, and in the rare
4343
// cases where this leads to an approximated type we recompute it with
4444
// the skolemized prefix. See the i6199* tests for usecases.
45-
val widenedAsf = new AsSeenFromMap(pre.info, cls)
45+
val widenedAsf = new AsSeenFromMap(pre.info, cls, approximateUnstablePrefixes)
4646
val ret = widenedAsf.apply(tp)
4747

4848
if widenedAsf.approxCount == 0 then
@@ -52,11 +52,11 @@ object TypeOps:
5252
case _ =>
5353
}
5454

55-
new AsSeenFromMap(pre, cls).apply(tp)
55+
new AsSeenFromMap(pre, cls, approximateUnstablePrefixes).apply(tp)
5656
}
5757

5858
/** The TypeMap handling the asSeenFrom */
59-
class AsSeenFromMap(pre: Type, cls: Symbol)(using Context) extends ApproximatingTypeMap, IdempotentCaptRefMap {
59+
class AsSeenFromMap(pre: Type, cls: Symbol, approximateUnstablePrefixes: Boolean)(using Context) extends ApproximatingTypeMap, IdempotentCaptRefMap {
6060

6161
/** The number of range approximations in invariant or contravariant positions
6262
* performed by this TypeMap.
@@ -81,7 +81,7 @@ object TypeOps:
8181
case pre: SuperType => toPrefix(pre.thistpe, cls, thiscls)
8282
case _ =>
8383
if (thiscls.derivesFrom(cls) && pre.baseType(thiscls).exists)
84-
if (variance <= 0 && !isLegalPrefix(pre))
84+
if (approximateUnstablePrefixes && variance <= 0 && !isLegalPrefix(pre))
8585
approxCount += 1
8686
range(defn.NothingType, pre)
8787
else pre

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1106,11 +1106,14 @@ object Types extends TypeUtils {
11061106

11071107
/** This type seen as if it were the type of a member of prefix type `pre`
11081108
* declared in class `cls`.
1109+
*
1110+
* @param approximateUnstablePrefixes - needed for mamberType method in quotes reflect API,
1111+
* where we want to approximate less
11091112
*/
1110-
final def asSeenFrom(pre: Type, cls: Symbol)(using Context): Type = {
1113+
final def asSeenFrom(pre: Type, cls: Symbol, approximateUnstablePrefixes: Boolean = true)(using Context): Type = {
11111114
record("asSeenFrom")
11121115
if (!cls.membersNeedAsSeenFrom(pre)) this
1113-
else TypeOps.asSeenFrom(this, pre, cls)
1116+
else TypeOps.asSeenFrom(this, pre, cls, approximateUnstablePrefixes)
11141117
}
11151118

11161119
// ----- Subtype-related --------------------------------------------

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

+1-6
Original file line numberDiff line numberDiff line change
@@ -1826,12 +1826,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
18261826
def termSymbol: Symbol = self.termSymbol
18271827
def isSingleton: Boolean = self.isSingleton
18281828
def memberType(member: Symbol): TypeRepr =
1829-
// we use thisType to avoid resolving otherwise unstable prefixes into Nothing
1830-
val classSymbol = self.classSymbol
1831-
member.info
1832-
.asSeenFrom(classSymbol.thisType, member.owner)
1833-
.substThis(classSymbol.asClass, self) // and we remove the previously added This(_) for compatibility
1834-
1829+
member.info.asSeenFrom(self, member.owner, approximateUnstablePrefixes = false)
18351830
def baseClasses: List[Symbol] = self.baseClasses
18361831
def baseType(cls: Symbol): TypeRepr = self.baseType(cls)
18371832
def derivesFrom(cls: Symbol): Boolean = self.derivesFrom(cls)

0 commit comments

Comments
 (0)