@@ -1993,7 +1993,6 @@ class Typer extends Namer
19931993 * (but do this at most once per tree).
19941994 *
19951995 * After that, two strategies are tried, and the first that is successful is picked.
1996- * If neither of the strategies are successful, continues with`fallBack`.
19971996 *
19981997 * 1st strategy: Try to insert `.apply` so that the result conforms to prototype `pt`.
19991998 * This strategy is not tried if the prototype represents already
@@ -2002,6 +2001,10 @@ class Typer extends Namer
20022001 * 2nd strategy: If tree is a select `qual.name`, try to insert an implicit conversion
20032002 * around the qualifier part `qual` so that the result conforms to the expected type
20042003 * with wildcard result type.
2004+ *
2005+ * If neither of the strategies are successful, continues with the `apply` result
2006+ * if an apply insertion was tried and `tree` has an `apply` method, or continues
2007+ * with `fallBack` otherwise. `fallBack` is supposed to always give an error.
20052008 */
20062009 def tryInsertApplyOrImplicit (tree : Tree , pt : ProtoType , locked : TypeVars )(fallBack : => Tree )(implicit ctx : Context ): Tree = {
20072010
@@ -2023,7 +2026,7 @@ class Typer extends Namer
20232026 else try adapt(simplify(sel, pt, locked), pt, locked) finally sel.removeAttachment(InsertedApply )
20242027 }
20252028
2026- def tryImplicit =
2029+ def tryImplicit ( fallBack : => Tree ) =
20272030 tryInsertImplicitOnQualifier(tree, pt, locked).getOrElse(fallBack)
20282031
20292032 pt match {
@@ -2034,8 +2037,17 @@ class Typer extends Namer
20342037 pt.markAsDropped()
20352038 tree
20362039 case _ =>
2037- if (isApplyProto(pt) || isMethod(tree) || isSyntheticApply(tree)) tryImplicit
2038- else tryEither(tryApply(_))((_, _) => tryImplicit)
2040+ if (isApplyProto(pt) || isMethod(tree) || isSyntheticApply(tree)) tryImplicit(fallBack)
2041+ else tryEither(tryApply(_)) { (app, appState) =>
2042+ tryImplicit {
2043+ if (tree.tpe.member(nme.apply).exists) {
2044+ // issue the error about the apply, since it is likely more informative than the fallback
2045+ appState.commit()
2046+ app
2047+ }
2048+ else fallBack
2049+ }
2050+ }
20392051 }
20402052 }
20412053
0 commit comments