Skip to content

Commit baaaa6c

Browse files
committed
Make i7044 typecheck with old version of recover
1 parent c7aea0e commit baaaa6c

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
@@ -3455,37 +3455,10 @@ class Typer extends Namer
34553455

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

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

0 commit comments

Comments
 (0)