Skip to content

Commit 4c27adf

Browse files
authored
Merge pull request #11069 from dotty-staging/fix-#11064
Special case comparisons between LazyRefs and bottom/top types
2 parents 8aae979 + 4e009c6 commit 4c27adf

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
306306
}
307307
compareWild
308308
case tp2: LazyRef =>
309-
!tp2.evaluating && recur(tp1, tp2.ref)
309+
isBottom(tp1) || !tp2.evaluating && recur(tp1, tp2.ref)
310310
case tp2: AnnotatedType if !tp2.isRefining =>
311311
recur(tp1, tp2.parent)
312312
case tp2: ThisType =>
@@ -373,7 +373,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
373373
if (recur(info1.alias, tp2)) return true
374374
if (tp1.prefix.isStable) return tryLiftedToThis1
375375
case _ =>
376-
if (tp1 eq NothingType) return true
376+
if (tp1 eq NothingType) || isBottom(tp1) then return true
377377
}
378378
thirdTry
379379
case tp1: TypeParamRef =>
@@ -420,7 +420,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
420420
// If `tp1` is in train of being evaluated, don't force it
421421
// because that would cause an assertionError. Return false instead.
422422
// See i859.scala for an example where we hit this case.
423-
!tp1.evaluating && recur(tp1.ref, tp2)
423+
tp2.isRef(AnyClass, skipRefined = false)
424+
|| !tp1.evaluating && recur(tp1.ref, tp2)
424425
case tp1: AnnotatedType if !tp1.isRefining =>
425426
recur(tp1.parent, tp2)
426427
case AndType(tp11, tp12) =>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait TypedArray[T, Repr]
2+
3+
trait Ops[T <: TypedArray[_, T]] {
4+
def typedArray(): T
5+
}
6+
7+
object Test {
8+
def test(ops: Ops[_ <: TypedArray[_ <: AnyRef, _]]) = ops.typedArray() // error: Recursion limit exceeded.
9+
}

tests/neg/i6225.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
object O1 { // error: cannot be instantiated
1+
object O1 {
22
type A[X] = X
33
opaque type T = A // error: opaque type alias must be fully applied
44
}
55

66
object O2 {
77
opaque type A[X] = X
8-
object A { // error: cannot be instantiated
8+
object A {
99
opaque type T = A // error: opaque type alias must be fully applied
1010
}
1111
}

tests/pos/i11064.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait TypedArray[T, Repr]
2+
3+
trait Ops[T <: TypedArray[_, T]] {
4+
def typedArray(): T
5+
}
6+
7+
object Test {
8+
def test(ops: Ops[_ <: TypedArray[_, _]]) = ops.typedArray()
9+
}

0 commit comments

Comments
 (0)