Skip to content

Commit 30ee52c

Browse files
committed
Revert specific conversion checking
# Conflicts: # compiler/src/dotty/tools/dotc/typer/Typer.scala
1 parent e15cd79 commit 30ee52c

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,11 @@ object Checking {
648648
else "Cannot override non-inline parameter with an inline parameter",
649649
p1.srcPos)
650650

651-
def checkConversionsSpecific(from: Type, to: Type, pos: SrcPos)(using Context): Unit =
652-
def fail(part: String, tp: Type) =
653-
report.error(em"the $part of an implicit conversion must be more specific than $tp", pos)
651+
def checkConversionsSpecific(to: Type, pos: SrcPos)(using Context): Unit =
654652
if to.isRef(defn.AnyValClass, skipRefined = false)
655653
|| to.isRef(defn.ObjectClass, skipRefined = false)
656-
then fail("result", to)
657-
if from.isBottomTypeAfterErasure
658-
then fail("argument", from)
654+
then
655+
report.error(em"the result of an implicit conversion must be more specific than $to", pos)
659656
}
660657

661658
trait Checking {

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

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,6 @@ class Typer extends Namer
537537
errorTree(tree, MissingIdent(tree, kind, name))
538538
end typedIdent
539539

540-
val newScheme: Boolean = true
541-
val dia: Boolean = false
542-
543540
/** Check that a stable identifier pattern is indeed stable (SLS 8.1.5)
544541
*/
545542
private def checkStableIdentPattern(tree: Tree, pt: Type)(using Context): Unit =
@@ -3581,27 +3578,40 @@ class Typer extends Namer
35813578
if canDefineFurther(wtp) then readapt(tree)
35823579
else err.typeMismatch(tree, pt, failure)
35833580

3584-
if pt.isInstanceOf[SelectionProto] then
3585-
tree // adaptations for selections are handled in typedSelect
3586-
else if ctx.mode.is(Mode.ImplicitsEnabled) && tree.tpe.isValueType then
3587-
checkConversionsSpecific(wtp, pt, tree.srcPos)
3588-
inferView(tree, pt) match {
3589-
case SearchSuccess(found, _, _, isExtension) =>
3590-
if isExtension then found
3591-
else
3592-
checkImplicitConversionUseOK(found)
3593-
withoutMode(Mode.ImplicitsEnabled)(readapt(found))
3594-
case failure: SearchFailure =>
3595-
if (pt.isInstanceOf[ProtoType] && !failure.isAmbiguous) then
3596-
// don't report the failure but return the tree unchanged. This
3597-
// will cause a failure at the next level out, which usually gives
3598-
// a better error message. To compensate, store the encountered failure
3599-
// as an attachment, so that it can be reported later as an addendum.
3600-
rememberSearchFailure(tree, failure)
3601-
tree
3602-
else recover(failure.reason)
3603-
}
3604-
else recover(NoMatchingImplicits)
3581+
pt match
3582+
case pt: SelectionProto =>
3583+
if ctx.gadt.nonEmpty then
3584+
// try GADT approximation if we're trying to select a member
3585+
// Member lookup cannot take GADTs into account b/c of cache, so we
3586+
// approximate types based on GADT constraints instead. For an example,
3587+
// see MemberHealing in gadt-approximation-interaction.scala.
3588+
gadts.println(i"Trying to heal member selection by GADT-approximating $wtp")
3589+
val gadtApprox = Inferencing.approximateGADT(wtp)
3590+
gadts.println(i"GADT-approximated $wtp ~~ $gadtApprox")
3591+
if pt.isMatchedBy(gadtApprox) then
3592+
gadts.println(i"Member selection healed by GADT approximation")
3593+
tpd.Typed(tree, TypeTree(gadtApprox))
3594+
else tree
3595+
else tree // other adaptations for selections are handled in typedSelect
3596+
case _ if ctx.mode.is(Mode.ImplicitsEnabled) && tree.tpe.isValueType =>
3597+
checkConversionsSpecific(pt, tree.srcPos)
3598+
inferView(tree, pt) match
3599+
case SearchSuccess(found, _, _, isExtension) =>
3600+
if isExtension then found
3601+
else
3602+
checkImplicitConversionUseOK(found)
3603+
withoutMode(Mode.ImplicitsEnabled)(readapt(found))
3604+
case failure: SearchFailure =>
3605+
if (pt.isInstanceOf[ProtoType] && !failure.isAmbiguous) then
3606+
// don't report the failure but return the tree unchanged. This
3607+
// will cause a failure at the next level out, which usually gives
3608+
// a better error message. To compensate, store the encountered failure
3609+
// as an attachment, so that it can be reported later as an addendum.
3610+
rememberSearchFailure(tree, failure)
3611+
tree
3612+
else recover(failure.reason)
3613+
case _ =>
3614+
recover(NoMatchingImplicits)
36053615
end adaptToSubType
36063616

36073617
def adaptType(tp: Type): Tree = {

0 commit comments

Comments
 (0)