@@ -175,33 +175,35 @@ object Types {
175
175
loop(this )
176
176
}
177
177
178
- /** Is phantom if upper bounded by XYZ.Any where XYZ extends scala.Phantom */
179
- final def isPhantom (implicit ctx : Context ): Boolean = {
180
- // note that the only phantom classes are PhantomAnyClass and PhantomNothingClass
181
- val sym = typeSymbol
182
- (sym eq defn.PhantomAny ) || (sym eq defn.PhantomNothing ) ||
183
- (! sym.isClass && (topType.classSymbol eq defn.PhantomAny ))
184
- }
185
-
186
178
/** Returns the top type of the lattice
187
179
* - XYX.Any if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any
188
180
* - scala.Any otherwise
189
181
*/
190
- final def topType (implicit ctx : Context ): TypeRef = widen match {
191
- case tp : ClassInfo if isPhantomClass(tp.classSymbol) => tp.prefix.select(tpnme.Any ).asInstanceOf [TypeRef ]
192
- case tp : TypeProxy if tp.superType ne this => tp.superType.topType
193
- case tp : AndOrType => tp.tp1.topType
194
- case _ => defn.AnyType
182
+ final def topType (implicit ctx : Context ): TypeRef = {
183
+ val lattice = phantomLatticeType
184
+ if (lattice.exists) lattice.select(tpnme.Any ).asInstanceOf [TypeRef ]
185
+ else defn.AnyType
195
186
}
196
187
197
188
/** Returns the bottom type of the lattice
198
189
* - XYZ.Nothing if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any
199
190
* - scala.Nothing otherwise
200
191
*/
201
- final def bottomType (implicit ctx : Context ): Type = topType match {
202
- case top : TypeRef if top.prefix.termSymbol ne defn.ScalaPackageVal =>
203
- top.prefix.select(tpnme.Nothing )
204
- case _ => defn.NothingType
192
+ final def bottomType (implicit ctx : Context ): Type = {
193
+ val lattice = phantomLatticeType
194
+ if (lattice.exists) lattice.select(tpnme.Nothing ).asInstanceOf [TypeRef ]
195
+ else defn.NothingType
196
+ }
197
+
198
+ /** Returns the type of the lattice
199
+ * - XYZ if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any
200
+ * - NoType otherwise
201
+ */
202
+ final def phantomLatticeType (implicit ctx : Context ): Type = widen match {
203
+ case tp : ClassInfo if isPhantomClass(tp.classSymbol) => tp.prefix
204
+ case tp : TypeProxy if tp.superType ne this => tp.superType.phantomLatticeType
205
+ case tp : AndOrType => tp.tp1.phantomLatticeType
206
+ case _ => NoType
205
207
}
206
208
207
209
/** If the symbol is of the class scala.Phantom.Any or scala.Phantom.Nothing */
@@ -3279,8 +3281,8 @@ object Types {
3279
3281
/** Type bounds >: lo <: hi */
3280
3282
abstract case class TypeBounds (lo : Type , hi : Type ) extends CachedProxyType with TypeType {
3281
3283
3282
- assert(lo.isInstanceOf [TermType ], lo )
3283
- assert(hi.isInstanceOf [TermType ], hi )
3284
+ assert(lo.isInstanceOf [TermType ])
3285
+ assert(hi.isInstanceOf [TermType ])
3284
3286
3285
3287
def variance : Int = 0
3286
3288
0 commit comments