Skip to content

Commit 2c01512

Browse files
authored
Merge pull request #9140 from dotty-staging/fix-9044
Quickly fix HKT GADT issue
2 parents fbafb72 + 2bb5d54 commit 2c01512

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,34 +3398,10 @@ class Typer extends Namer
33983398

33993399
// try an implicit conversion
34003400
val prevConstraint = ctx.typerState.constraint
3401-
def recover(failure: SearchFailureType) = {
3402-
def canTryGADTHealing: Boolean = {
3403-
val isDummy = tree.hasAttachment(dummyTreeOfType.IsDummyTree)
3404-
tryGadtHealing // allow GADT healing only once to avoid a loop
3405-
&& ctx.gadt.nonEmpty // GADT healing only makes sense if there are GADT constraints present
3406-
&& !isDummy // avoid healing a dummy tree as it can lead to an error in a very specific case
3407-
}
3408-
3401+
def recover(failure: SearchFailureType) =
34093402
if (isFullyDefined(wtp, force = ForceDegree.all) &&
34103403
ctx.typerState.constraint.ne(prevConstraint)) readapt(tree)
3411-
else if (canTryGADTHealing) {
3412-
// try recovering with a GADT approximation
3413-
val nestedCtx = ctx.fresh.setNewTyperState()
3414-
val res =
3415-
readapt(
3416-
tree = tpd.Typed(tree, TypeTree(Inferencing.approximateGADT(wtp))),
3417-
shouldTryGadtHealing = false,
3418-
)(using nestedCtx)
3419-
if (!nestedCtx.reporter.hasErrors) {
3420-
// GADT recovery successful
3421-
nestedCtx.typerState.commit()
3422-
res
3423-
} else {
3424-
// otherwise fail with the error that would have been reported without the GADT recovery
3425-
err.typeMismatch(tree, pt, failure)
3426-
}
3427-
} else err.typeMismatch(tree, pt, failure)
3428-
}
3404+
else err.typeMismatch(tree, pt, failure)
34293405
if ctx.mode.is(Mode.ImplicitsEnabled) && tree.typeOpt.isValueType then
34303406
if pt.isRef(defn.AnyValClass) || pt.isRef(defn.ObjectClass) then
34313407
ctx.error(em"the result of an implicit conversion must be more specific than $pt", tree.sourcePos)

tests/neg/i9044.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sealed trait Test[+F[_], +A] extends Product with Serializable
2+
3+
object Test {
4+
5+
implicit class Syntax[F[_], A](val self: Test[F, A]) extends AnyVal {
6+
7+
def fold[B](completed: F[A] => B): B = self match {
8+
case Completed(fa) => completed(fa) // error
9+
}
10+
}
11+
12+
13+
final case class Completed[F[_], A](fa: F[A]) extends Test[F, A]
14+
}
File renamed without changes.

0 commit comments

Comments
 (0)