Skip to content

Commit 7bf179f

Browse files
committed
Push ObjectTpeJava handling into a version of typeIsAny
1 parent 477edc1 commit 7bf179f

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

src/reflect/scala/reflect/internal/TypeDebugging.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ trait TypeDebugging {
133133
def refine(defs: Scope): String = defs.toList.mkString("{", " ;\n ", "}")
134134
def bounds(lo: Type, hi: Type): String = {
135135
val lo_s = if (typeIsNothing(lo)) "" else s" >: $lo"
136-
val hi_s = if (typeIsAny(hi)) "" else s" <: $hi"
136+
val hi_s = if (typeIsAnyOrJavaObject(hi)) "" else s" <: $hi"
137137
lo_s + hi_s
138138
}
139139
}

src/reflect/scala/reflect/internal/Types.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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.eq(definitions.ObjectTpeJava) || hi.isWildcard
1545+
private def emptyUpperBound = typeIsAnyOrJavaObject(hi) || hi.isWildcard
15461546
def isEmptyBounds = emptyLowerBound && emptyUpperBound
15471547

15481548
override def safeToString = scalaNotation(_.toString)
@@ -3541,7 +3541,7 @@ trait Types
35413541
if (typeIsNothing(tp)) { // kind-polymorphic
35423542
addBound(NothingTpe)
35433543
true
3544-
} else if(typeIsAny(tp)) { // kind-polymorphic
3544+
} else if(typeIsAnyExactly(tp)) { // kind-polymorphic
35453545
addBound(AnyTpe)
35463546
true
35473547
} else if (params.isEmpty) {
@@ -5210,9 +5210,17 @@ trait Types
52105210
}
52115211

52125212
@tailrec
5213-
private[scala] final def typeIsAny(tp: Type): Boolean =
5213+
private[scala] final def typeIsAnyOrJavaObject(tp: Type): Boolean =
52145214
tp.dealias match {
5215-
case PolyType(_, tp) => typeIsAny(tp)
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 =
5222+
tp.dealias match {
5223+
case PolyType(_, tp) => typeIsAnyExactly(tp)
52165224
case TypeRef(_, AnyClass, _) => true
52175225
case _ => false
52185226
}

src/reflect/scala/reflect/internal/tpe/TypeConstraints.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private[internal] trait TypeConstraints {
9797
* only guards against being created with them.]
9898
*/
9999
private[this] var lobounds = lo0 filterNot typeIsNothing
100-
private[this] var hibounds = hi0 filterNot typeIsAny
100+
private[this] var hibounds = hi0 filterNot typeIsAnyOrJavaObject
101101
private[this] var numlo = numlo0
102102
private[this] var numhi = numhi0
103103
private[this] var avoidWidening = avoidWidening0
@@ -143,7 +143,7 @@ private[internal] trait TypeConstraints {
143143
def addHiBound(tp: Type, isNumericBound: Boolean = false): Unit = {
144144
// My current test case only demonstrates the need to let Nothing through as
145145
// a lower bound, but I suspect the situation is symmetrical.
146-
val mustConsider = typeIsAny(tp) || !(hibounds contains tp)
146+
val mustConsider = typeIsAnyOrJavaObject(tp) || !(hibounds contains tp)
147147
if (mustConsider) {
148148
checkWidening(tp)
149149
if (isNumericBound && isNumericValueType(tp)) {
@@ -182,7 +182,7 @@ private[internal] trait TypeConstraints {
182182
case tp :: Nil => " >: " + tp
183183
case tps => tps.mkString(" >: (", ", ", ")")
184184
}
185-
val hi = hiBounds filterNot typeIsAny match {
185+
val hi = hiBounds filterNot typeIsAnyOrJavaObject match {
186186
case Nil => ""
187187
case tp :: Nil => " <: " + tp
188188
case tps => tps.mkString(" <: (", ", ", ")")

test/junit/scala/reflect/internal/TypesTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,10 @@ class TypesTest {
319319
val aSym = typeOf[Foo.type].member(TermName("a"))
320320
val nSym = typeOf[Foo.type].member(TermName("n"))
321321

322-
assert(typeIsAny(AnyTpe))
322+
assert(typeIsAnyOrJavaObject(AnyTpe))
323323
assert(typeIsNothing(NothingTpe))
324-
assert(!typeIsAny(LiteralType(Constant(1))))
325-
assert(!typeIsAny(SingleType(NoPrefix, aSym)))
324+
assert(!typeIsAnyOrJavaObject(LiteralType(Constant(1))))
325+
assert(!typeIsAnyOrJavaObject(SingleType(NoPrefix, aSym)))
326326
assert(!typeIsNothing(SingleType(NoPrefix, nSym)))
327327
}
328328

0 commit comments

Comments
 (0)