@@ -372,17 +372,30 @@ object SymDenotations {
372372 case _ => unforcedDecls.openForMutations
373373 }
374374
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 empty bounds.
376+ * At the same time, integrate the original alias as a refinement of the
377+ * self type of the enclosing class.
376378 */
377379 final def normalizeOpaque ()(implicit ctx : Context ) = {
378380 def abstractRHS (tp : Type ): Type = tp match {
379381 case tp : HKTypeLambda => tp.derivedLambdaType(resType = abstractRHS(tp.resType))
380382 case _ => defn.AnyType
381383 }
382- if (isOpaqueHelper ) {
384+ if (isOpaqueAlias ) {
383385 info match {
384386 case TypeAlias (alias) =>
385387 info = TypeBounds (defn.NothingType , abstractRHS(alias))
388+
389+ def refineSelfType (selfType : Type ) =
390+ RefinedType (selfType, name, TypeAlias (alias))
391+ val enclClassInfo = owner.asClass.classInfo
392+ enclClassInfo.selfInfo match {
393+ case self : Type =>
394+ owner.info = enclClassInfo.derivedClassInfo(selfInfo = refineSelfType(self))
395+ case self : Symbol =>
396+ self.info = refineSelfType(self.info)
397+ }
398+
386399 setFlag(Deferred )
387400 case _ =>
388401 }
@@ -553,18 +566,14 @@ object SymDenotations {
553566 final def isAbstractOrParamType (implicit ctx : Context ): Boolean = this is DeferredOrTypeParam
554567
555568 /** Is this symbol a user-defined opaque alias type? */
556- def isOpaqueAlias (implicit ctx : Context ): Boolean = is(Opaque , butNot = Synthetic )
569+ def isOpaqueAlias (implicit ctx : Context ): Boolean = is(Opaque ) && ! isClass
557570
558- /** Is this symbol the companion of an opaque alias type ? */
559- def isOpaqueCompanion (implicit ctx : Context ): Boolean = is(OpaqueModule )
571+ /** Is this symbol a module that contains of an opaque aliases ? */
572+ def containsOpaques (implicit ctx : Context ): Boolean = is(Opaque ) && isClass
560573
561- /** Is this symbol a synthetic opaque type inside an opaque companion object? */
562- def isOpaqueHelper (implicit ctx : Context ): Boolean = is(SyntheticOpaque , butNot = Module )
563-
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
574+ def seesOpaques (implicit ctx : Context ): Boolean =
575+ containsOpaques ||
576+ is(Module , butNot = Package ) && owner.containsOpaques
568577
569578 /** Is this the denotation of a self symbol of some class?
570579 * This is the case if one of two conditions holds:
@@ -789,7 +798,7 @@ object SymDenotations {
789798 */
790799 def membersNeedAsSeenFrom (pre : Type )(implicit ctx : Context ): Boolean =
791800 ! ( this .isTerm
792- || this .isStaticOwner && ! this .isOpaqueCompanion
801+ || this .isStaticOwner && ! this .seesOpaques
793802 || ctx.erasedTypes
794803 || (pre eq NoPrefix )
795804 || (pre eq thisType)
@@ -1029,16 +1038,6 @@ object SymDenotations {
10291038 */
10301039 final def companionModule (implicit ctx : Context ): Symbol =
10311040 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- }
10421041 else registeredCompanion.sourceModule
10431042
10441043 private def companionType (implicit ctx : Context ): Symbol =
@@ -1053,13 +1052,6 @@ object SymDenotations {
10531052 final def companionClass (implicit ctx : Context ): Symbol =
10541053 companionType.suchThat(_.isClass).symbol
10551054
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-
10631055 final def scalacLinkedClass (implicit ctx : Context ): Symbol =
10641056 if (this is ModuleClass ) companionNamed(effectiveName.toTypeName)
10651057 else if (this .isClass) companionNamed(effectiveName.moduleClassName).sourceModule.moduleClass
@@ -1109,15 +1101,17 @@ object SymDenotations {
11091101 final def enclosingSubClass (implicit ctx : Context ): Symbol =
11101102 ctx.owner.ownersIterator.findSymbol(_.isSubClass(symbol))
11111103
1112- /** The alias of a synthetic opaque type that's stored in the self type of the
1104+ /** The alias of an opaque type alias that's stored in the self type of the
11131105 * containing object.
11141106 */
11151107 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
1108+ def recur (tp : Type ): Type = tp match {
1109+ case RefinedType (parent, rname, TypeAlias (alias)) =>
1110+ if (rname == name) alias else recur(parent)
1111+ case _ =>
1112+ NoType
1113+ }
1114+ recur(owner.asClass.classInfo.selfType)
11211115 }
11221116
11231117 /** The non-private symbol whose name and type matches the type of this symbol
@@ -1974,7 +1968,7 @@ object SymDenotations {
19741968
19751969 /** Register companion class */
19761970 override def registerCompanion (companion : Symbol )(implicit ctx : Context ) =
1977- if (companion.canHaveCompanion && ! unforcedIsAbsent && ! companion.unforcedIsAbsent)
1971+ if (companion.isClass && ! unforcedIsAbsent && ! companion.unforcedIsAbsent)
19781972 myCompanion = companion
19791973
19801974 override def registeredCompanion (implicit ctx : Context ) = { ensureCompleted(); myCompanion }
0 commit comments