@@ -879,19 +879,25 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
879879 */
880880 def trySelectUnapply (qual : untpd.Tree )(fallBack : Tree => Tree ): Tree = {
881881 // 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)
886892 } {
887893 (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 )
891896 } {
892897 (_, _) => fallBack(sel)
893898 }
894899 }
900+ }
895901 // try first for unapply, then for unapplySeq
896902 tryWithName(nme.unapply) {
897903 sel => tryWithName(nme.unapplySeq)(_ => fallBack(sel)) // for backwards compatibility; will be dropped
0 commit comments