@@ -879,19 +879,25 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
879
879
*/
880
880
def trySelectUnapply (qual : untpd.Tree )(fallBack : Tree => Tree ): Tree = {
881
881
// try first for non-overloaded, then for overloaded ocurrences
882
- def tryWithName (name : TermName )(fallBack : Tree => Tree )(implicit ctx : Context ): Tree =
883
- tryEither { implicit ctx =>
884
- val specificProto = new UnapplyFunProto (selType, this )
885
- typedExpr(untpd.Select (qual, name), specificProto)
882
+ def tryWithName (name : TermName )(fallBack : Tree => Tree )(implicit ctx : Context ): Tree = {
883
+ def tryWithProto (pt : Type )(implicit ctx : Context ) = {
884
+ val result = typedExpr(untpd.Select (qual, name), new UnapplyFunProto (pt, this ))
885
+ if (! result.symbol.exists || result.symbol.name == name) result
886
+ else notAnExtractor(result)
887
+ // It might be that the result of typedExpr is an `apply` selection or implicit conversion.
888
+ // Reject in this case.
889
+ }
890
+ tryEither {
891
+ implicit ctx => tryWithProto(selType)
886
892
} {
887
893
(sel, _) =>
888
- tryEither { implicit ctx =>
889
- val genericProto = new UnapplyFunProto (WildcardType , this )
890
- typedExpr(untpd.Select (qual, name), genericProto)
894
+ tryEither {
895
+ implicit ctx => tryWithProto(WildcardType )
891
896
} {
892
897
(_, _) => fallBack(sel)
893
898
}
894
899
}
900
+ }
895
901
// try first for unapply, then for unapplySeq
896
902
tryWithName(nme.unapply) {
897
903
sel => tryWithName(nme.unapplySeq)(_ => fallBack(sel)) // for backwards compatibility; will be dropped
0 commit comments