Skip to content

Backport "Rollback constraints in compareAppliedTypeParamRef" to 3.3 LTS #180

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 1 commit into from
Mar 18, 2025
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
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1143,8 +1143,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
tl => otherTycon.appliedTo(bodyArgs(tl)))
else
otherTycon
(assumedTrue(tycon) || directionalIsSubType(tycon, adaptedTycon)) &&
directionalRecur(adaptedTycon.appliedTo(args), other)
rollbackConstraintsUnless:
(assumedTrue(tycon) || directionalIsSubType(tycon, adaptedTycon))
&& directionalRecur(adaptedTycon.appliedTo(args), other)
}
}
end compareAppliedTypeParamRef
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/20519.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Box[T](val value: T)

def boo[F[_], A](e: F[Box[A]]): F[A] = ???

type Result[G[_], B] = G[Box[B]]

def main =
val b: Result[Option, Int] = ???
val c = boo(b)
c: Option[Int]
16 changes: 16 additions & 0 deletions tests/pos/20519b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
trait TCl[F[_]]

def boo[F[_], A](e: F[Option[A]], ev: TCl[F]): Unit = ()

type Result[F[_], A] = F[Option[A]]

@main def main =
summon[Result[Option, Int] =:= Option[Option[Int]]]

val ev = new TCl[Option] {}

val b: Result[Option, Int] = None
boo(b, ev)

val b2: Option[Option[Int]] = None
boo(b2, ev)
20 changes: 20 additions & 0 deletions tests/pos/20519c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
object Main {
trait TCl[F[_]]

implicit class Stx[F[_], A](e: F[Option[A]]) {
def boo(implicit ev: TCl[F]): Unit = ()
}

type Result[F[_], A] = F[Option[A]]

implicit val t: TCl[Option] = new TCl[Option] {}

def main(args: Array[String]): Unit = {
val b: Result[Option, Int] = None
b.boo

// works without the alias:
val b2: Option[Option[Int]] = None
b2.boo
}
}