@@ -60,6 +60,7 @@ object Typer {
6060 assert(tree.pos.exists, s " position not set for $tree # ${tree.uniqueId}" )
6161
6262 private val ExprOwner = new Property .Key [Symbol ]
63+ private val InsertedApply = new Property .Key [Unit ]
6364}
6465
6566class Typer extends Namer with TypeAssigner with Applications with Implicits with Dynamic with Checking with Docstrings {
@@ -1818,9 +1819,17 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18181819 */
18191820 def tryInsertApplyOrImplicit (tree : Tree , pt : ProtoType )(fallBack : => Tree )(implicit ctx : Context ): Tree = {
18201821
1822+ def isSyntheticApply (tree : Tree ): Boolean = tree match {
1823+ case tree : Select => tree.getAttachment(InsertedApply ).isDefined
1824+ case Apply (fn, _) => fn.getAttachment(InsertedApply ).isDefined
1825+ case _ => false
1826+ }
1827+
18211828 def tryApply (implicit ctx : Context ) = {
18221829 val sel = typedSelect(untpd.Select (untpd.TypedSplice (tree), nme.apply), pt)
1823- if (sel.tpe.isError) sel else adapt(sel, pt)
1830+ sel.pushAttachment(InsertedApply , ())
1831+ if (sel.tpe.isError) sel
1832+ else try adapt(sel, pt) finally sel.removeAttachment(InsertedApply )
18241833 }
18251834
18261835 def tryImplicit =
@@ -1832,7 +1841,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18321841 pt.markAsDropped()
18331842 tree
18341843 case _ =>
1835- if (isApplyProto(pt)) tryImplicit
1844+ if (isApplyProto(pt) || isSyntheticApply(tree) ) tryImplicit
18361845 else tryEither(tryApply(_))((_, _) => tryImplicit)
18371846 }
18381847 }
0 commit comments