@@ -537,9 +537,6 @@ class Typer extends Namer
537
537
errorTree(tree, MissingIdent (tree, kind, name))
538
538
end typedIdent
539
539
540
- val newScheme : Boolean = true
541
- val dia : Boolean = false
542
-
543
540
/** Check that a stable identifier pattern is indeed stable (SLS 8.1.5)
544
541
*/
545
542
private def checkStableIdentPattern (tree : Tree , pt : Type )(using Context ): Unit =
@@ -3581,27 +3578,40 @@ class Typer extends Namer
3581
3578
if canDefineFurther(wtp) then readapt(tree)
3582
3579
else err.typeMismatch(tree, pt, failure)
3583
3580
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 )
3605
3615
end adaptToSubType
3606
3616
3607
3617
def adaptType (tp : Type ): Tree = {
0 commit comments