@@ -1542,7 +1542,7 @@ trait Types
15421542 case _ => lo <:< that && that <:< hi
15431543 }
15441544 private def emptyLowerBound = typeIsNothing(lo) || lo.isWildcard
1545- private def emptyUpperBound = typeIsAny (hi) || hi.isWildcard
1545+ private def emptyUpperBound = typeIsAnyOrJavaObject (hi) || hi.isWildcard
15461546 def isEmptyBounds = emptyLowerBound && emptyUpperBound
15471547
15481548 override def safeToString = scalaNotation(_.toString)
@@ -2409,7 +2409,11 @@ trait Types
24092409 if (this eq other.asInstanceOf [AnyRef ]) true
24102410 else other match {
24112411 case otherTypeRef : TypeRef =>
2412- Objects .equals(pre, otherTypeRef.pre) && sym.eq(otherTypeRef.sym) && sameElementsEquals(args, otherTypeRef.args)
2412+ Objects .equals(pre, otherTypeRef.pre) &&
2413+ sym.eq(otherTypeRef.sym) &&
2414+ sameElementsEquals(args, otherTypeRef.args) &&
2415+ // `ObjectTpeJavaRef` is not structurally equal to `ObjectTpe` -- they should not be collapsed by `unique`
2416+ ! (this .isInstanceOf [ObjectTpeJavaRef ] || otherTypeRef.isInstanceOf [ObjectTpeJavaRef ])
24132417 case _ => false
24142418 }
24152419 }
@@ -2706,18 +2710,21 @@ trait Types
27062710 private final class ClassArgsTypeRef (pre : Type , sym : Symbol , args : List [Type ]) extends ArgsTypeRef (pre, sym, args)
27072711 private final class AliasNoArgsTypeRef (pre : Type , sym : Symbol ) extends NoArgsTypeRef (pre, sym) with AliasTypeRef
27082712 private final class AbstractNoArgsTypeRef (pre : Type , sym : Symbol ) extends NoArgsTypeRef (pre, sym) with AbstractTypeRef
2709- private final class ClassNoArgsTypeRef (pre : Type , sym : Symbol ) extends NoArgsTypeRef (pre, sym){
2713+ private final class ClassNoArgsTypeRef (pre : Type , sym : Symbol ) extends NoArgsTypeRef (pre, sym) {
27102714 override def contains (sym0 : Symbol ): Boolean = (sym eq sym0) || pre.contains(sym0)
27112715 }
27122716
2713- /** Expose ClassNoArgsTypeRef so we can create a non-uniqued ObjectTpeJava here and in reflect
2714- *
2715- * NOTE:
2716- * - definitions.ObjectTpe is forced first, so that it ends up in the unique cache.
2717- * - the created TypeRef is structurally equal to ObjectTpe, but with its own identity
2718- * - we don't want the TypeRef we create here to be unique'd
2719- */
2720- private [scala] def mkObjectTpeJava : Type = new ClassNoArgsTypeRef (definitions.ObjectTpe .prefix, definitions.ObjectClass )
2717+ /** Expose ObjectTpeJavaRef so we can create a non-uniqued ObjectTpeJava
2718+ * (using a type test rather than `eq`, which causes cycles).
2719+ *
2720+ * NOTE:
2721+ * - definitions.ObjectTpe is forced first, so that it ends up in the unique cache.
2722+ * - the created TypeRef is structurally equal to ObjectTpe, but with its own identity
2723+ * - we don't want the TypeRef we create here to be unique'd
2724+ */
2725+ private [internal] final class ObjectTpeJavaRef extends NoArgsTypeRef (definitions.ObjectTpe .prefix, definitions.ObjectClass ) {
2726+ override def contains (sym0 : Symbol ): Boolean = (sym eq sym0) || pre.contains(sym0)
2727+ }
27212728
27222729 object TypeRef extends TypeRefExtractor {
27232730 def apply (pre : Type , sym : Symbol , args : List [Type ]): Type = unique({
@@ -3534,7 +3541,7 @@ trait Types
35343541 if (typeIsNothing(tp)) { // kind-polymorphic
35353542 addBound(NothingTpe )
35363543 true
3537- } else if (typeIsAny (tp)) { // kind-polymorphic
3544+ } else if (typeIsAnyExactly (tp)) { // kind-polymorphic
35383545 addBound(AnyTpe )
35393546 true
35403547 } else if (params.isEmpty) {
@@ -5203,9 +5210,17 @@ trait Types
52035210 }
52045211
52055212 @ tailrec
5206- private [scala] final def typeIsAny (tp : Type ): Boolean =
5213+ private [scala] final def typeIsAnyOrJavaObject (tp : Type ): Boolean =
5214+ tp.dealias match {
5215+ case PolyType (_, tp) => typeIsAnyOrJavaObject(tp)
5216+ case TypeRef (_, AnyClass , _) => true
5217+ case _ : ObjectTpeJavaRef => true
5218+ case _ => false
5219+ }
5220+
5221+ private [scala] final def typeIsAnyExactly (tp : Type ): Boolean =
52075222 tp.dealias match {
5208- case PolyType (_, tp) => typeIsAny (tp)
5223+ case PolyType (_, tp) => typeIsAnyExactly (tp)
52095224 case TypeRef (_, AnyClass , _) => true
52105225 case _ => false
52115226 }
0 commit comments