Skip to content

Commit

Permalink
Push ObjectTpeJava handling into a version of typeIsAny
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym committed May 13, 2019
1 parent 477edc1 commit 7bf179f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/TypeDebugging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ trait TypeDebugging {
def refine(defs: Scope): String = defs.toList.mkString("{", " ;\n ", "}")
def bounds(lo: Type, hi: Type): String = {
val lo_s = if (typeIsNothing(lo)) "" else s" >: $lo"
val hi_s = if (typeIsAny(hi)) "" else s" <: $hi"
val hi_s = if (typeIsAnyOrJavaObject(hi)) "" else s" <: $hi"
lo_s + hi_s
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/reflect/scala/reflect/internal/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ trait Types
case _ => lo <:< that && that <:< hi
}
private def emptyLowerBound = typeIsNothing(lo) || lo.isWildcard
private def emptyUpperBound = typeIsAny(hi) || hi.eq(definitions.ObjectTpeJava) || hi.isWildcard
private def emptyUpperBound = typeIsAnyOrJavaObject(hi) || hi.isWildcard
def isEmptyBounds = emptyLowerBound && emptyUpperBound

override def safeToString = scalaNotation(_.toString)
Expand Down Expand Up @@ -3541,7 +3541,7 @@ trait Types
if (typeIsNothing(tp)) { // kind-polymorphic
addBound(NothingTpe)
true
} else if(typeIsAny(tp)) { // kind-polymorphic
} else if(typeIsAnyExactly(tp)) { // kind-polymorphic
addBound(AnyTpe)
true
} else if (params.isEmpty) {
Expand Down Expand Up @@ -5210,9 +5210,17 @@ trait Types
}

@tailrec
private[scala] final def typeIsAny(tp: Type): Boolean =
private[scala] final def typeIsAnyOrJavaObject(tp: Type): Boolean =
tp.dealias match {
case PolyType(_, tp) => typeIsAny(tp)
case PolyType(_, tp) => typeIsAnyOrJavaObject(tp)
case TypeRef(_, AnyClass, _) => true
case _: ObjectTpeJavaRef => true
case _ => false
}

private[scala] final def typeIsAnyExactly(tp: Type): Boolean =
tp.dealias match {
case PolyType(_, tp) => typeIsAnyExactly(tp)
case TypeRef(_, AnyClass, _) => true
case _ => false
}
Expand Down
6 changes: 3 additions & 3 deletions src/reflect/scala/reflect/internal/tpe/TypeConstraints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private[internal] trait TypeConstraints {
* only guards against being created with them.]
*/
private[this] var lobounds = lo0 filterNot typeIsNothing
private[this] var hibounds = hi0 filterNot typeIsAny
private[this] var hibounds = hi0 filterNot typeIsAnyOrJavaObject
private[this] var numlo = numlo0
private[this] var numhi = numhi0
private[this] var avoidWidening = avoidWidening0
Expand Down Expand Up @@ -143,7 +143,7 @@ private[internal] trait TypeConstraints {
def addHiBound(tp: Type, isNumericBound: Boolean = false): Unit = {
// My current test case only demonstrates the need to let Nothing through as
// a lower bound, but I suspect the situation is symmetrical.
val mustConsider = typeIsAny(tp) || !(hibounds contains tp)
val mustConsider = typeIsAnyOrJavaObject(tp) || !(hibounds contains tp)
if (mustConsider) {
checkWidening(tp)
if (isNumericBound && isNumericValueType(tp)) {
Expand Down Expand Up @@ -182,7 +182,7 @@ private[internal] trait TypeConstraints {
case tp :: Nil => " >: " + tp
case tps => tps.mkString(" >: (", ", ", ")")
}
val hi = hiBounds filterNot typeIsAny match {
val hi = hiBounds filterNot typeIsAnyOrJavaObject match {
case Nil => ""
case tp :: Nil => " <: " + tp
case tps => tps.mkString(" <: (", ", ", ")")
Expand Down
6 changes: 3 additions & 3 deletions test/junit/scala/reflect/internal/TypesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ class TypesTest {
val aSym = typeOf[Foo.type].member(TermName("a"))
val nSym = typeOf[Foo.type].member(TermName("n"))

assert(typeIsAny(AnyTpe))
assert(typeIsAnyOrJavaObject(AnyTpe))
assert(typeIsNothing(NothingTpe))
assert(!typeIsAny(LiteralType(Constant(1))))
assert(!typeIsAny(SingleType(NoPrefix, aSym)))
assert(!typeIsAnyOrJavaObject(LiteralType(Constant(1))))
assert(!typeIsAnyOrJavaObject(SingleType(NoPrefix, aSym)))
assert(!typeIsNothing(SingleType(NoPrefix, nSym)))
}

Expand Down

0 comments on commit 7bf179f

Please sign in to comment.