Skip to content

Consider aliases of Any as top #19735

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

Closed
wants to merge 1 commit into from
Closed
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
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 @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i19610.min1.scala
Original file line number Diff line number Diff line change
@@ -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] {})
}
12 changes: 12 additions & 0 deletions tests/pos/i19610.orig.scala
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tests/pos/i19610.scala
Original file line number Diff line number Diff line change
@@ -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