diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 78e22b7b76b9..438cf14a2bb5 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -255,7 +255,7 @@ object Types extends TypeUtils { /** Is this type exactly `Any`, or a type lambda ending in `Any`? */ def isTopOfSomeKind(using Context): Boolean = dealias match case tp: TypeLambda => tp.resType.isTopOfSomeKind - case _ => isExactlyAny + case _ => dealias.isExactlyAny def isBottomType(using Context): Boolean = if ctx.mode.is(Mode.SafeNulls) && !ctx.phase.erasedTypes then hasClassSymbol(defn.NothingClass) diff --git a/tests/pos/i19610.min1.scala b/tests/pos/i19610.min1.scala new file mode 100644 index 000000000000..48b98fc8a41c --- /dev/null +++ b/tests/pos/i19610.min1.scala @@ -0,0 +1,9 @@ +final case class Wrap[T <: U](first: A[T])(using A[T] <:< A[N]) +sealed trait A[+T] +type U = Any +type N = Nothing + +@main def main = { + // Error: Cannot prove that A[U] <:< A[N]. + Wrap(new A[N] {}) +} diff --git a/tests/pos/i19610.orig.scala b/tests/pos/i19610.orig.scala new file mode 100644 index 000000000000..fa053ae1555f --- /dev/null +++ b/tests/pos/i19610.orig.scala @@ -0,0 +1,12 @@ +// Error: Cannot prove that A[U] <:< A[N]. +def res1: Unit = Wrap(new A[N]{}) + +// Adding the obvious type argument to Wrap makes it compile just fine. +def res2: Unit = Wrap[N](new A[N]{}) + +final case class Wrap[T <: U](first: A[T])(using A[T] <:< A[N]) + +sealed trait A[+T] + +type U = Any +type N = Nothing diff --git a/tests/pos/i19610.scala b/tests/pos/i19610.scala new file mode 100644 index 000000000000..1762c0e5456f --- /dev/null +++ b/tests/pos/i19610.scala @@ -0,0 +1,14 @@ +type Top = Any +type Bot = Nothing + +sealed trait Cov[+A] + +final case class Wrap1[B <: Top](first: Cov[B])(using Cov[B] <:< Cov[Bot]) +final case class Wrap2[B <: Any](first: Cov[B])(using Cov[B] <:< Cov[Bot]) + +class Test: + def t10 = Wrap1/* */(new Cov[Bot] {}) // error: Cannot prove that Cov[Top] <:< Cov[Bot] + def t11 = Wrap1[Bot](new Cov[Bot] {}) // ok + + def t20 = Wrap2/* */(new Cov[Bot] {}) // ok + def t21 = Wrap2[Bot](new Cov[Bot] {}) // ok