Skip to content

Commit

Permalink
Special case comparison with Any
Browse files Browse the repository at this point in the history
Add the rule T <: Any for any *-Type T. This was not include fully before. We
did have the rule that T <: Any, if Any is in the base types of T. However,
it could be that the base type wrt Any does not exist. Example:

    Any#L <: Any

yielded false before, now yields true. This error manifested itself in i4031.scala.

With the new rule, we can drop again the special case in derivedSelect.

TODO: in the context of scala#4108, this seems questionable. Also, `Any#L` seems an
invalid type (even tho it is sound to consider it empty), and we'd probably not
want to accept it if the user writes it; here it is only OK because it's
introduced by avoidance. Or are user-written types checked elsewhere?
  • Loading branch information
odersky authored and Blaisorblade committed Dec 2, 2018
1 parent 1644303 commit db6aaa3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
if (cls2 eq AnyKindClass) return true
if (tp1.isRef(NothingClass)) return true
if (tp1.isLambdaSub) return false
if (cls2 eq AnyClass) return true
// Note: We would like to replace this by `if (tp1.hasHigherKind)`
// but right now we cannot since some parts of the standard library rely on the
// idiom that e.g. `List <: Any`. We have to bootstrap without scalac first.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4588,7 +4588,7 @@ object Types {
forwarded.orElse(
range(super.derivedSelect(tp, preLo).loBound, super.derivedSelect(tp, preHi).hiBound))
case _ =>
if (pre == defn.AnyType) pre else super.derivedSelect(tp, pre) match {
super.derivedSelect(tp, pre) match {
case TypeBounds(lo, hi) => range(lo, hi)
case tp => tp
}
Expand Down

0 comments on commit db6aaa3

Please sign in to comment.