@@ -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 {
@@ -1706,7 +1707,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
17061707
17071708 def typed (tree : untpd.Tree , pt : Type = WildcardType )(implicit ctx : Context ): Tree = /* >|>*/ ctx.traceIndented (i " typing $tree" , typr, show = true ) /* <|<*/ {
17081709 assertPositioned(tree)
1709- try adapt(typedUnadapted(tree, pt), pt, tree )
1710+ try adapt(typedUnadapted(tree, pt), pt)
17101711 catch {
17111712 case ex : CyclicReference => errorTree(tree, cyclicErrorMsg(ex))
17121713 case ex : TypeError => errorTree(tree, ex.getMessage)
@@ -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 }
@@ -1845,7 +1854,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18451854 case Select (qual, name) =>
18461855 val qualProto = SelectionProto (name, pt, NoViewsAllowed , privateOK = false )
18471856 tryEither { implicit ctx =>
1848- val qual1 = adaptInterpolated(qual, qualProto, EmptyTree )
1857+ val qual1 = adaptInterpolated(qual, qualProto)
18491858 if ((qual eq qual1) || ctx.reporter.hasErrors) None
18501859 else Some (typed(cpy.Select (tree)(untpd.TypedSplice (qual1), name), pt))
18511860 } { (_, _) => None
@@ -1854,12 +1863,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18541863 }
18551864 }
18561865
1857- def adapt (tree : Tree , pt : Type , original : untpd. Tree = untpd. EmptyTree )(implicit ctx : Context ): Tree = /* >|>*/ track(" adapt" ) /* <|<*/ {
1866+ def adapt (tree : Tree , pt : Type )(implicit ctx : Context ): Tree = /* >|>*/ track(" adapt" ) /* <|<*/ {
18581867 /* >|>*/ ctx.traceIndented(i " adapting $tree of type ${tree.tpe} to $pt" , typr, show = true ) /* <|<*/ {
18591868 if (tree.isDef) interpolateUndetVars(tree, tree.symbol)
18601869 else if (! tree.tpe.widen.isInstanceOf [LambdaType ]) interpolateUndetVars(tree, NoSymbol )
18611870 tree.overwriteType(tree.tpe.simplified)
1862- adaptInterpolated(tree, pt, original )
1871+ adaptInterpolated(tree, pt)
18631872 }
18641873 }
18651874
@@ -1901,7 +1910,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
19011910 * (14) When in mode EXPRmode, apply a view
19021911 * If all this fails, error
19031912 */
1904- def adaptInterpolated (tree : Tree , pt : Type , original : untpd. Tree )(implicit ctx : Context ): Tree = {
1913+ def adaptInterpolated (tree : Tree , pt : Type )(implicit ctx : Context ): Tree = {
19051914
19061915 assert(pt.exists)
19071916
@@ -1919,7 +1928,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
19191928 TermRef .withSigAndDenot(ref.prefix, ref.name, alt.info.signature, alt))
19201929 resolveOverloaded(alts, pt) match {
19211930 case alt :: Nil =>
1922- adapt(tree.withType(alt), pt, original )
1931+ adapt(tree.withType(alt), pt)
19231932 case Nil =>
19241933 def noMatches =
19251934 errorTree(tree,
@@ -1956,7 +1965,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
19561965 def adaptToArgs (wtp : Type , pt : FunProto ): Tree = wtp match {
19571966 case _ : MethodOrPoly =>
19581967 if (pt.args.lengthCompare(1 ) > 0 && isUnary(wtp) && ctx.canAutoTuple)
1959- adaptInterpolated(tree, pt.tupled, original )
1968+ adaptInterpolated(tree, pt.tupled)
19601969 else
19611970 tree
19621971 case _ => tryInsertApplyOrImplicit(tree, pt) {
@@ -1992,7 +2001,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
19922001
19932002 def adaptNoArgs (wtp : Type ): Tree = wtp match {
19942003 case wtp : ExprType =>
1995- adaptInterpolated(tree.withType(wtp.resultType), pt, original )
2004+ adaptInterpolated(tree.withType(wtp.resultType), pt)
19962005 case wtp : ImplicitMethodType if constrainResult(wtp, followAlias(pt)) =>
19972006 val tvarsToInstantiate = tvarsInParams(tree)
19982007 wtp.paramInfos.foreach(instantiateSelected(_, tvarsToInstantiate))
@@ -2108,7 +2117,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
21082117 ! (isSyntheticApply(tree) && ! isExpandableApply))
21092118 typed(etaExpand(tree, wtp, arity), pt)
21102119 else if (wtp.paramInfos.isEmpty && isAutoApplied(tree.symbol))
2111- adaptInterpolated(tpd.Apply (tree, Nil ), pt, EmptyTree )
2120+ adaptInterpolated(tpd.Apply (tree, Nil ), pt)
21122121 else if (wtp.isImplicit)
21132122 err.typeMismatch(tree, pt)
21142123 else
@@ -2212,7 +2221,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
22122221 val prevConstraint = ctx.typerState.constraint
22132222 if (pt.isInstanceOf [ProtoType ] && ! failure.isInstanceOf [AmbiguousImplicits ]) tree
22142223 else if (isFullyDefined(wtp, force = ForceDegree .all) &&
2215- ctx.typerState.constraint.ne(prevConstraint)) adapt(tree, pt, original )
2224+ ctx.typerState.constraint.ne(prevConstraint)) adapt(tree, pt)
22162225 else err.typeMismatch(tree, pt, failure)
22172226 }
22182227 }
@@ -2249,7 +2258,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
22492258 pt match {
22502259 case pt : FunProto
22512260 if pt.args.lengthCompare(1 ) > 0 && isUnary(ref) && ctx.canAutoTuple =>
2252- adaptInterpolated(tree, pt.tupled, original )
2261+ adaptInterpolated(tree, pt.tupled)
22532262 case _ =>
22542263 adaptOverloaded(ref)
22552264 }
@@ -2262,7 +2271,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
22622271 }
22632272 if (typeArgs.isEmpty) typeArgs = constrained(poly, tree)._2
22642273 convertNewGenericArray(
2265- adaptInterpolated(tree.appliedToTypeTrees(typeArgs), pt, original ))
2274+ adaptInterpolated(tree.appliedToTypeTrees(typeArgs), pt))
22662275 }
22672276 case wtp =>
22682277 if (isStructuralTermSelect(tree)) adapt(handleStructural(tree), pt)
0 commit comments