Skip to content

Commit e09e489

Browse files
committed
Make i7044 typecheck with old version of recover
1 parent 027d7dd commit e09e489

File tree

3 files changed

+9
-34
lines changed

3 files changed

+9
-34
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
751751
case _ => false
752752
}
753753
case _ => false
754-
comparePaths || isNewSubType(tp1.underlying.widenExpr)
754+
comparePaths || isSubType(tp1.underlying.widenExpr, tp2, approx.addLow)
755755
case tp1: RefinedType =>
756756
isNewSubType(tp1.parent)
757757
case tp1: RecType =>

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,12 @@ object Inferencing {
198198
* - If we have A <: Int and F <: [A] => Option[A] (note the invariance),
199199
* then we should approximate F[A] ~~ Option[A]. That is, we should
200200
* respect the invariance of the type constructor.
201-
* - If we have A <: Option[B] and B <: Int, we approximate A ~~ Option[Int].
202-
* That is, we recursively approximate all nested GADT-constrained types.
203-
* This is certain to be sound (because we maintain necessary subtyping),
204-
* but not accurate.
201+
* - If we have A <: Option[B] and B <: Int, we approximate A ~~
202+
* Option[B]. That is, we don't recurse into already approximated
203+
* types. Since GADT approximation is (for now) only used for member
204+
* selection, this behaviour is expected, as nested types cannot affect
205+
* member selection (note that given/extension lookup doesn't need GADT
206+
* approx, see gadt-approximation-interaction.scala).
205207
*/
206208
def apply(tp: Type): Type = tp.dealias match {
207209
case tp @ TypeRef(qual, nme) if (qual eq NoPrefix)

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

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,37 +3458,10 @@ class Typer extends Namer
34583458

34593459
// try an implicit conversion
34603460
val prevConstraint = ctx.typerState.constraint
3461-
def recover(failure: SearchFailureType) = {
3462-
def canTryGADTHealing: Boolean = {
3463-
def isDummy = tree.hasAttachment(dummyTreeOfType.IsDummyTree)
3464-
tryGadtHealing // allow GADT healing only once to avoid a loop
3465-
&& ctx.gadt.nonEmpty // GADT healing only makes sense if there are GADT constraints present
3466-
&& !isDummy // avoid healing a dummy tree as it can lead to an error in a very specific case
3467-
}
3468-
3461+
def recover(failure: SearchFailureType) =
34693462
if (isFullyDefined(wtp, force = ForceDegree.all) &&
34703463
ctx.typerState.constraint.ne(prevConstraint)) readapt(tree)
3471-
else if (canTryGADTHealing) {
3472-
// try recovering with a GADT approximation
3473-
// note: this seems be be important only in a very specific case
3474-
// where we select a member from so
3475-
val nestedCtx = ctx.fresh.setNewTyperState()
3476-
val ascribed = tpd.Typed(tree, TypeTree(gadtApprox))
3477-
val res =
3478-
readapt(
3479-
tree = ascribed,
3480-
shouldTryGadtHealing = false,
3481-
)(using nestedCtx)
3482-
if (!nestedCtx.reporter.hasErrors) {
3483-
// GADT recovery successful
3484-
nestedCtx.typerState.commit()
3485-
res
3486-
} else {
3487-
// otherwise fail with the error that would have been reported without the GADT recovery
3488-
err.typeMismatch(tree, pt, failure)
3489-
}
3490-
} else err.typeMismatch(tree, pt, failure)
3491-
}
3464+
else err.typeMismatch(tree, pt, failure)
34923465

34933466
if ctx.mode.is(Mode.ImplicitsEnabled) && tree.typeOpt.isValueType then
34943467
if pt.isRef(defn.AnyValClass) || pt.isRef(defn.ObjectClass) then

0 commit comments

Comments
 (0)