@@ -858,6 +858,13 @@ object Types {
858
858
case _ => defn.AnyClass .typeRef
859
859
}
860
860
861
+ /** the self type of the underlying classtype */
862
+ def givenSelfType (implicit ctx : Context ): Type = this match {
863
+ case tp @ RefinedType (parent, name) => tp.wrapIfMember(parent.givenSelfType)
864
+ case tp : TypeProxy => tp.underlying.givenSelfType
865
+ case _ => NoType
866
+ }
867
+
861
868
/** The parameter types of a PolyType or MethodType, Empty list for others */
862
869
final def paramTypess (implicit ctx : Context ): List [List [Type ]] = this match {
863
870
case mt : MethodType => mt.paramTypes :: mt.resultType.paramTypess
@@ -1781,7 +1788,12 @@ object Types {
1781
1788
if (false ) RefinedType (parent, refinedName, refinedInfo)
1782
1789
else RefinedType (parent, refinedName, rt => refinedInfo.substSkolem(this , SkolemType (rt)))
1783
1790
}
1784
-
1791
+
1792
+ /** Add this refinement to `parent`, provided If `refinedName` is a member of `parent`. */
1793
+ def wrapIfMember (parent : Type )(implicit ctx : Context ): Type =
1794
+ if (parent.member(refinedName).exists) derivedRefinedType(parent, refinedName, refinedInfo)
1795
+ else parent
1796
+
1785
1797
override def equals (that : Any ) = that match {
1786
1798
case that : RefinedType =>
1787
1799
this .parent == that.parent &&
@@ -2398,22 +2410,27 @@ object Types {
2398
2410
* - the fully applied reference to the class itself.
2399
2411
*/
2400
2412
def selfType (implicit ctx : Context ): Type = {
2401
- if (selfTypeCache == null ) {
2402
- def fullRef = fullyAppliedRef(cls.typeRef, cls.typeParams)
2403
- def withFullRef (tp : Type ): Type =
2404
- if (ctx.erasedTypes) fullRef else AndType (tp, fullRef)
2405
- selfTypeCache = selfInfo match {
2406
- case NoType =>
2407
- fullRef
2408
- case tp : Type =>
2409
- if (cls is Module ) tp else withFullRef(tp)
2410
- case self : Symbol =>
2411
- assert(! (cls is Module ))
2412
- withFullRef(self.info)
2413
+ if (selfTypeCache == null )
2414
+ selfTypeCache = {
2415
+ def fullRef = fullyAppliedRef(cls.typeRef, cls.typeParams)
2416
+ val given = givenSelfType
2417
+ val raw =
2418
+ if (! given .exists) fullRef
2419
+ else if (cls is Module ) given
2420
+ else if (ctx.erasedTypes) fullRef
2421
+ else AndType (given , fullRef)
2422
+ raw// .asSeenFrom(prefix, cls.owner)
2413
2423
}
2414
- }
2415
2424
selfTypeCache
2416
2425
}
2426
+
2427
+ /** The explicitly given self type (self types of modules are assumed to be
2428
+ * explcitly given here).
2429
+ */
2430
+ override def givenSelfType (implicit ctx : Context ): Type = selfInfo match {
2431
+ case tp : Type => tp
2432
+ case self : Symbol => self.info
2433
+ }
2417
2434
2418
2435
private var selfTypeCache : Type = null
2419
2436
0 commit comments