Skip to content

Special case comparisons between LazyRefs and bottom/top types #11069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
}
compareWild
case tp2: LazyRef =>
!tp2.evaluating && recur(tp1, tp2.ref)
isBottom(tp1) || !tp2.evaluating && recur(tp1, tp2.ref)
case tp2: AnnotatedType if !tp2.isRefining =>
recur(tp1, tp2.parent)
case tp2: ThisType =>
Expand Down Expand Up @@ -373,7 +373,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
if (recur(info1.alias, tp2)) return true
if (tp1.prefix.isStable) return tryLiftedToThis1
case _ =>
if (tp1 eq NothingType) return true
if (tp1 eq NothingType) || isBottom(tp1) then return true
}
thirdTry
case tp1: TypeParamRef =>
Expand Down Expand Up @@ -420,7 +420,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
// If `tp1` is in train of being evaluated, don't force it
// because that would cause an assertionError. Return false instead.
// See i859.scala for an example where we hit this case.
!tp1.evaluating && recur(tp1.ref, tp2)
tp2.isRef(AnyClass, skipRefined = false)
|| !tp1.evaluating && recur(tp1.ref, tp2)
case tp1: AnnotatedType if !tp1.isRefining =>
recur(tp1.parent, tp2)
case AndType(tp11, tp12) =>
Expand Down
9 changes: 9 additions & 0 deletions tests/neg-custom-args/allow-deep-subtypes/i11064.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait TypedArray[T, Repr]

trait Ops[T <: TypedArray[_, T]] {
def typedArray(): T
}

object Test {
def test(ops: Ops[_ <: TypedArray[_ <: AnyRef, _]]) = ops.typedArray() // error: Recursion limit exceeded.
}
4 changes: 2 additions & 2 deletions tests/neg/i6225.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
object O1 { // error: cannot be instantiated
object O1 {
type A[X] = X
opaque type T = A // error: opaque type alias must be fully applied
}

object O2 {
opaque type A[X] = X
object A { // error: cannot be instantiated
object A {
opaque type T = A // error: opaque type alias must be fully applied
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i11064.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait TypedArray[T, Repr]

trait Ops[T <: TypedArray[_, T]] {
def typedArray(): T
}

object Test {
def test(ops: Ops[_ <: TypedArray[_, _]]) = ops.typedArray()
}