Skip to content

Try either when compare an intersection against an applied type in GADT mode #15175

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
9 changes: 9 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,14 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
case _ => false
} && { GADTused = true; true }

def tryGadtAnd1: Boolean =
ctx.mode.is(Mode.GadtConstraintInference) && {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ctx.mode.is(Mode.GadtConstraintInference) && {
necessaryConstraintsOnly && {

Perhaps is better?

tp1 match
case AndType(tp11, tp12) =>
either(recur(tp11, tp2), recur(tp12, tp2))
case _ => false
}

tycon2 match {
case param2: TypeParamRef =>
isMatchingApply(tp1) ||
Expand All @@ -1213,6 +1221,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
case info2: ClassInfo =>
tycon2.name.startsWith("Tuple") &&
defn.isTupleNType(tp2) && recur(tp1, tp2.toNestedPairs) ||
tryGadtAnd1 ||
tryBaseType(info2.cls)
case _ =>
fourthTry
Expand Down
21 changes: 21 additions & 0 deletions tests/neg/i11545.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Taken from
// https://github.com/lampepfl/dotty/issues/11545#issuecomment-787609144
class test0 {
type AA
trait S[A]
trait Inv[A]

class P[X] extends S[Inv[X] & AA]

}

@main def test: Unit =
new test0:
type AA = Inv[String]

def patmat[A, Y](s: S[Inv[A] & Y]): A = s match {
case p: P[x] =>
"Hello" // error
}

val got: Int = patmat[Int, AA](new P)