@@ -372,18 +372,38 @@ object SymDenotations {
372
372
case _ => unforcedDecls.openForMutations
373
373
}
374
374
375
- /** If this is a synthetic opaque type alias, mark it as Deferred with empty bounds
375
+ /** If this is a synthetic opaque type alias, mark it as Deferred with bounds
376
+ * as given by the right hand side's `WithBounds` annotation, if one is present,
377
+ * or with empty bounds of the right kind, otherwise.
378
+ * At the same time, integrate the original alias as a refinement of the
379
+ * self type of the enclosing class.
376
380
*/
377
381
final def normalizeOpaque ()(implicit ctx : Context ) = {
378
382
def abstractRHS (tp : Type ): Type = tp match {
379
383
case tp : HKTypeLambda => tp.derivedLambdaType(resType = abstractRHS(tp.resType))
380
384
case _ => defn.AnyType
381
385
}
382
- if (isOpaqueHelper ) {
386
+ if (isOpaqueAlias ) {
383
387
info match {
384
388
case TypeAlias (alias) =>
385
- info = TypeBounds (defn.NothingType , abstractRHS(alias))
389
+ val (refiningAlias, bounds) = alias match {
390
+ case AnnotatedType (alias1, Annotation .WithBounds (bounds)) =>
391
+ (alias1, bounds)
392
+ case _ =>
393
+ (alias, TypeBounds (defn.NothingType , abstractRHS(alias)))
394
+ }
395
+ def refineSelfType (selfType : Type ) =
396
+ RefinedType (selfType, name, TypeAlias (refiningAlias))
397
+ val enclClassInfo = owner.asClass.classInfo
398
+ enclClassInfo.selfInfo match {
399
+ case self : Type =>
400
+ owner.info = enclClassInfo.derivedClassInfo(selfInfo = refineSelfType(self))
401
+ case self : Symbol =>
402
+ self.info = refineSelfType(self.info)
403
+ }
404
+ info = bounds
386
405
setFlag(Deferred )
406
+ typeRef.recomputeDenot()
387
407
case _ =>
388
408
}
389
409
}
@@ -553,18 +573,14 @@ object SymDenotations {
553
573
final def isAbstractOrParamType (implicit ctx : Context ): Boolean = this is DeferredOrTypeParam
554
574
555
575
/** Is this symbol a user-defined opaque alias type? */
556
- def isOpaqueAlias (implicit ctx : Context ): Boolean = is(Opaque , butNot = Synthetic )
557
-
558
- /** Is this symbol the companion of an opaque alias type? */
559
- def isOpaqueCompanion (implicit ctx : Context ): Boolean = is(OpaqueModule )
576
+ def isOpaqueAlias (implicit ctx : Context ): Boolean = is(Opaque ) && ! isClass
560
577
561
- /** Is this symbol a synthetic opaque type inside an opaque companion object ? */
562
- def isOpaqueHelper (implicit ctx : Context ): Boolean = is(SyntheticOpaque , butNot = Module )
578
+ /** Is this symbol a module that contains opaque aliases ? */
579
+ def containsOpaques (implicit ctx : Context ): Boolean = is(Opaque ) && isClass
563
580
564
- /** Can this symbol have a companion module?
565
- * This is the case if it is a class or an opaque type alias.
566
- */
567
- final def canHaveCompanion (implicit ctx : Context ) = isClass || isOpaqueAlias
581
+ def seesOpaques (implicit ctx : Context ): Boolean =
582
+ containsOpaques ||
583
+ is(Module , butNot = Package ) && owner.containsOpaques
568
584
569
585
/** Is this the denotation of a self symbol of some class?
570
586
* This is the case if one of two conditions holds:
@@ -789,7 +805,7 @@ object SymDenotations {
789
805
*/
790
806
def membersNeedAsSeenFrom (pre : Type )(implicit ctx : Context ): Boolean =
791
807
! ( this .isTerm
792
- || this .isStaticOwner && ! this .isOpaqueCompanion
808
+ || this .isStaticOwner && ! this .seesOpaques
793
809
|| ctx.erasedTypes
794
810
|| (pre eq NoPrefix )
795
811
|| (pre eq thisType)
@@ -1029,16 +1045,6 @@ object SymDenotations {
1029
1045
*/
1030
1046
final def companionModule (implicit ctx : Context ): Symbol =
1031
1047
if (is(Module )) sourceModule
1032
- else if (isOpaqueAlias) {
1033
- def reference (tp : Type ): Symbol = tp match {
1034
- case TypeRef (prefix : TermRef , _) => prefix.termSymbol
1035
- case tp : HKTypeLambda => reference(tp.resType)
1036
- case tp : AppliedType => reference(tp.tycon)
1037
- case tp : ErrorType => registeredCompanion.sourceModule
1038
- }
1039
- val TypeAlias (alias) = info
1040
- reference(alias)
1041
- }
1042
1048
else registeredCompanion.sourceModule
1043
1049
1044
1050
private def companionType (implicit ctx : Context ): Symbol =
@@ -1053,13 +1059,6 @@ object SymDenotations {
1053
1059
final def companionClass (implicit ctx : Context ): Symbol =
1054
1060
companionType.suchThat(_.isClass).symbol
1055
1061
1056
- /** The opaque type with the same (type-) name as this module or module class,
1057
- * and which is also defined in the same scope and compilation unit.
1058
- * NoSymbol if this type does not exist.
1059
- */
1060
- final def companionOpaqueType (implicit ctx : Context ): Symbol =
1061
- companionType.suchThat(_.isOpaqueAlias).symbol
1062
-
1063
1062
final def scalacLinkedClass (implicit ctx : Context ): Symbol =
1064
1063
if (this is ModuleClass ) companionNamed(effectiveName.toTypeName)
1065
1064
else if (this .isClass) companionNamed(effectiveName.moduleClassName).sourceModule.moduleClass
@@ -1109,15 +1108,17 @@ object SymDenotations {
1109
1108
final def enclosingSubClass (implicit ctx : Context ): Symbol =
1110
1109
ctx.owner.ownersIterator.findSymbol(_.isSubClass(symbol))
1111
1110
1112
- /** The alias of a synthetic opaque type that's stored in the self type of the
1111
+ /** The alias of an opaque type alias that's stored in the self type of the
1113
1112
* containing object.
1114
1113
*/
1115
1114
def opaqueAlias (implicit ctx : Context ): Type = {
1116
- if (isOpaqueHelper)
1117
- owner.asClass.classInfo.selfType match {
1118
- case RefinedType (_, _, bounds) => bounds.extractOpaqueAlias
1119
- }
1120
- else NoType
1115
+ def recur (tp : Type ): Type = tp match {
1116
+ case RefinedType (parent, rname, TypeAlias (alias)) =>
1117
+ if (rname == name) alias else recur(parent)
1118
+ case _ =>
1119
+ NoType
1120
+ }
1121
+ recur(owner.asClass.classInfo.selfType)
1121
1122
}
1122
1123
1123
1124
/** The non-private symbol whose name and type matches the type of this symbol
@@ -1974,7 +1975,7 @@ object SymDenotations {
1974
1975
1975
1976
/** Register companion class */
1976
1977
override def registerCompanion (companion : Symbol )(implicit ctx : Context ) =
1977
- if (companion.canHaveCompanion && ! unforcedIsAbsent && ! companion.unforcedIsAbsent)
1978
+ if (companion.isClass && ! unforcedIsAbsent && ! companion.unforcedIsAbsent)
1978
1979
myCompanion = companion
1979
1980
1980
1981
override def registeredCompanion (implicit ctx : Context ) = { ensureCompleted(); myCompanion }
0 commit comments