@@ -1993,7 +1993,6 @@ class Typer extends Namer
1993
1993
* (but do this at most once per tree).
1994
1994
*
1995
1995
* 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`.
1997
1996
*
1998
1997
* 1st strategy: Try to insert `.apply` so that the result conforms to prototype `pt`.
1999
1998
* This strategy is not tried if the prototype represents already
@@ -2002,6 +2001,10 @@ class Typer extends Namer
2002
2001
* 2nd strategy: If tree is a select `qual.name`, try to insert an implicit conversion
2003
2002
* around the qualifier part `qual` so that the result conforms to the expected type
2004
2003
* 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.
2005
2008
*/
2006
2009
def tryInsertApplyOrImplicit (tree : Tree , pt : ProtoType , locked : TypeVars )(fallBack : => Tree )(implicit ctx : Context ): Tree = {
2007
2010
@@ -2023,7 +2026,7 @@ class Typer extends Namer
2023
2026
else try adapt(simplify(sel, pt, locked), pt, locked) finally sel.removeAttachment(InsertedApply )
2024
2027
}
2025
2028
2026
- def tryImplicit =
2029
+ def tryImplicit ( fallBack : => Tree ) =
2027
2030
tryInsertImplicitOnQualifier(tree, pt, locked).getOrElse(fallBack)
2028
2031
2029
2032
pt match {
@@ -2034,8 +2037,17 @@ class Typer extends Namer
2034
2037
pt.markAsDropped()
2035
2038
tree
2036
2039
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
+ }
2039
2051
}
2040
2052
}
2041
2053
0 commit comments