@@ -60,6 +60,7 @@ object Typer {
60
60
assert(tree.pos.exists, s " position not set for $tree # ${tree.uniqueId}" )
61
61
62
62
private val ExprOwner = new Property .Key [Symbol ]
63
+ private val InsertedApply = new Property .Key [Unit ]
63
64
}
64
65
65
66
class 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
1706
1707
1707
1708
def typed (tree : untpd.Tree , pt : Type = WildcardType )(implicit ctx : Context ): Tree = /* >|>*/ ctx.traceIndented (i " typing $tree" , typr, show = true ) /* <|<*/ {
1708
1709
assertPositioned(tree)
1709
- try adapt(typedUnadapted(tree, pt), pt, tree )
1710
+ try adapt(typedUnadapted(tree, pt), pt)
1710
1711
catch {
1711
1712
case ex : CyclicReference => errorTree(tree, cyclicErrorMsg(ex))
1712
1713
case ex : TypeError => errorTree(tree, ex.getMessage)
@@ -1818,9 +1819,17 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1818
1819
*/
1819
1820
def tryInsertApplyOrImplicit (tree : Tree , pt : ProtoType )(fallBack : => Tree )(implicit ctx : Context ): Tree = {
1820
1821
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
+
1821
1828
def tryApply (implicit ctx : Context ) = {
1822
1829
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 )
1824
1833
}
1825
1834
1826
1835
def tryImplicit =
@@ -1832,7 +1841,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1832
1841
pt.markAsDropped()
1833
1842
tree
1834
1843
case _ =>
1835
- if (isApplyProto(pt)) tryImplicit
1844
+ if (isApplyProto(pt) || isSyntheticApply(tree) ) tryImplicit
1836
1845
else tryEither(tryApply(_))((_, _) => tryImplicit)
1837
1846
}
1838
1847
}
@@ -1845,7 +1854,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1845
1854
case Select (qual, name) =>
1846
1855
val qualProto = SelectionProto (name, pt, NoViewsAllowed , privateOK = false )
1847
1856
tryEither { implicit ctx =>
1848
- val qual1 = adaptInterpolated(qual, qualProto, EmptyTree )
1857
+ val qual1 = adaptInterpolated(qual, qualProto)
1849
1858
if ((qual eq qual1) || ctx.reporter.hasErrors) None
1850
1859
else Some (typed(cpy.Select (tree)(untpd.TypedSplice (qual1), name), pt))
1851
1860
} { (_, _) => None
@@ -1854,12 +1863,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1854
1863
}
1855
1864
}
1856
1865
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" ) /* <|<*/ {
1858
1867
/* >|>*/ ctx.traceIndented(i " adapting $tree of type ${tree.tpe} to $pt" , typr, show = true ) /* <|<*/ {
1859
1868
if (tree.isDef) interpolateUndetVars(tree, tree.symbol)
1860
1869
else if (! tree.tpe.widen.isInstanceOf [LambdaType ]) interpolateUndetVars(tree, NoSymbol )
1861
1870
tree.overwriteType(tree.tpe.simplified)
1862
- adaptInterpolated(tree, pt, original )
1871
+ adaptInterpolated(tree, pt)
1863
1872
}
1864
1873
}
1865
1874
@@ -1901,7 +1910,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1901
1910
* (14) When in mode EXPRmode, apply a view
1902
1911
* If all this fails, error
1903
1912
*/
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 = {
1905
1914
1906
1915
assert(pt.exists)
1907
1916
@@ -1919,7 +1928,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1919
1928
TermRef .withSigAndDenot(ref.prefix, ref.name, alt.info.signature, alt))
1920
1929
resolveOverloaded(alts, pt) match {
1921
1930
case alt :: Nil =>
1922
- adapt(tree.withType(alt), pt, original )
1931
+ adapt(tree.withType(alt), pt)
1923
1932
case Nil =>
1924
1933
def noMatches =
1925
1934
errorTree(tree,
@@ -1956,7 +1965,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1956
1965
def adaptToArgs (wtp : Type , pt : FunProto ): Tree = wtp match {
1957
1966
case _ : MethodOrPoly =>
1958
1967
if (pt.args.lengthCompare(1 ) > 0 && isUnary(wtp) && ctx.canAutoTuple)
1959
- adaptInterpolated(tree, pt.tupled, original )
1968
+ adaptInterpolated(tree, pt.tupled)
1960
1969
else
1961
1970
tree
1962
1971
case _ => tryInsertApplyOrImplicit(tree, pt) {
@@ -1992,7 +2001,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1992
2001
1993
2002
def adaptNoArgs (wtp : Type ): Tree = wtp match {
1994
2003
case wtp : ExprType =>
1995
- adaptInterpolated(tree.withType(wtp.resultType), pt, original )
2004
+ adaptInterpolated(tree.withType(wtp.resultType), pt)
1996
2005
case wtp : ImplicitMethodType if constrainResult(wtp, followAlias(pt)) =>
1997
2006
val tvarsToInstantiate = tvarsInParams(tree)
1998
2007
wtp.paramInfos.foreach(instantiateSelected(_, tvarsToInstantiate))
@@ -2108,7 +2117,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
2108
2117
! (isSyntheticApply(tree) && ! isExpandableApply))
2109
2118
typed(etaExpand(tree, wtp, arity), pt)
2110
2119
else if (wtp.paramInfos.isEmpty && isAutoApplied(tree.symbol))
2111
- adaptInterpolated(tpd.Apply (tree, Nil ), pt, EmptyTree )
2120
+ adaptInterpolated(tpd.Apply (tree, Nil ), pt)
2112
2121
else if (wtp.isImplicit)
2113
2122
err.typeMismatch(tree, pt)
2114
2123
else
@@ -2212,7 +2221,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
2212
2221
val prevConstraint = ctx.typerState.constraint
2213
2222
if (pt.isInstanceOf [ProtoType ] && ! failure.isInstanceOf [AmbiguousImplicits ]) tree
2214
2223
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)
2216
2225
else err.typeMismatch(tree, pt, failure)
2217
2226
}
2218
2227
}
@@ -2249,7 +2258,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
2249
2258
pt match {
2250
2259
case pt : FunProto
2251
2260
if pt.args.lengthCompare(1 ) > 0 && isUnary(ref) && ctx.canAutoTuple =>
2252
- adaptInterpolated(tree, pt.tupled, original )
2261
+ adaptInterpolated(tree, pt.tupled)
2253
2262
case _ =>
2254
2263
adaptOverloaded(ref)
2255
2264
}
@@ -2262,7 +2271,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
2262
2271
}
2263
2272
if (typeArgs.isEmpty) typeArgs = constrained(poly, tree)._2
2264
2273
convertNewGenericArray(
2265
- adaptInterpolated(tree.appliedToTypeTrees(typeArgs), pt, original ))
2274
+ adaptInterpolated(tree.appliedToTypeTrees(typeArgs), pt))
2266
2275
}
2267
2276
case wtp =>
2268
2277
if (isStructuralTermSelect(tree)) adapt(handleStructural(tree), pt)
0 commit comments