@@ -589,6 +589,7 @@ object Trees {
589589 case class Inlined [- T >: Untyped ] private [ast] (call : tpd.Tree , bindings : List [MemberDef [T ]], expansion : Tree [T ])
590590 extends Tree [T ] {
591591 type ThisTree [- T >: Untyped ] = Inlined [T ]
592+ override def initialPos = call.pos
592593 }
593594
594595 /** A type tree that represents an existing or inferred type */
@@ -922,6 +923,11 @@ object Trees {
922923 case ys => Thicket (ys)
923924 }
924925
926+ /** Extractor for the synthetic scrutinee tree of an implicit match */
927+ object ImplicitScrutinee {
928+ def apply () = Ident (nme.IMPLICITkw )
929+ def unapply (id : Ident ): Boolean = id.name == nme.IMPLICITkw && ! id.isInstanceOf [BackquotedIdent ]
930+ }
925931 // ----- Helper classes for copying, transforming, accumulating -----------------
926932
927933 val cpy : TreeCopier
@@ -1109,6 +1115,10 @@ object Trees {
11091115 case tree : Annotated if (arg eq tree.arg) && (annot eq tree.annot) => tree
11101116 case _ => finalize(tree, untpd.Annotated (arg, annot))
11111117 }
1118+ def UntypedSplice (tree : Tree )(splice : untpd.Tree ) = tree match {
1119+ case tree : tpd.UntypedSplice if tree.splice `eq` splice => tree
1120+ case _ => finalize(tree, tpd.UntypedSplice (splice))
1121+ }
11121122 def Thicket (tree : Tree )(trees : List [Tree ]): Thicket = tree match {
11131123 case tree : Thicket if trees eq tree.trees => tree
11141124 case _ => finalize(tree, untpd.Thicket (trees))
@@ -1146,7 +1156,7 @@ object Trees {
11461156 */
11471157 protected def inlineContext (call : Tree )(implicit ctx : Context ): Context = ctx
11481158
1149- abstract class TreeMap (val cpy : TreeCopier = inst.cpy) {
1159+ abstract class TreeMap (val cpy : TreeCopier = inst.cpy) { self =>
11501160
11511161 def transform (tree : Tree )(implicit ctx : Context ): Tree = {
11521162 Stats .record(s " TreeMap.transform $getClass" )
@@ -1245,8 +1255,8 @@ object Trees {
12451255 case Thicket (trees) =>
12461256 val trees1 = transform(trees)
12471257 if (trees1 eq trees) tree else Thicket (trees1)
1248- case _ if ctx.reporter.errorsReported =>
1249- tree
1258+ case _ =>
1259+ transformMoreCases( tree)
12501260 }
12511261 }
12521262
@@ -1258,9 +1268,26 @@ object Trees {
12581268 transform(tree).asInstanceOf [Tr ]
12591269 def transformSub [Tr <: Tree ](trees : List [Tr ])(implicit ctx : Context ): List [Tr ] =
12601270 transform(trees).asInstanceOf [List [Tr ]]
1271+
1272+ protected def transformMoreCases (tree : Tree )(implicit ctx : Context ): Tree = tree match {
1273+ case tpd.UntypedSplice (usplice) =>
1274+ // For a typed tree map: homomorphism on the untyped part with
1275+ // recursive mapping of typed splices.
1276+ // The case is overridden in UntypedTreeMap.##
1277+ val untpdMap = new untpd.UntypedTreeMap {
1278+ override def transform (tree : untpd.Tree )(implicit ctx : Context ): untpd.Tree = tree match {
1279+ case untpd.TypedSplice (tsplice) =>
1280+ untpd.cpy.TypedSplice (tree)(self.transform(tsplice).asInstanceOf [tpd.Tree ])
1281+ // the cast is safe, since the UntypedSplice case is overridden in UntypedTreeMap.
1282+ case _ => super .transform(tree)
1283+ }
1284+ }
1285+ cpy.UntypedSplice (tree)(untpdMap.transform(usplice))
1286+ case _ if ctx.reporter.errorsReported => tree
1287+ }
12611288 }
12621289
1263- abstract class TreeAccumulator [X ] {
1290+ abstract class TreeAccumulator [X ] { self =>
12641291 // Ties the knot of the traversal: call `foldOver(x, tree))` to dive in the `tree` node.
12651292 def apply (x : X , tree : Tree )(implicit ctx : Context ): X
12661293
@@ -1355,14 +1382,29 @@ object Trees {
13551382 this (this (x, arg), annot)
13561383 case Thicket (ts) =>
13571384 this (x, ts)
1358- case _ if ctx.reporter.errorsReported || ctx.mode.is(Mode .Interactive ) =>
1359- // In interactive mode, errors might come from previous runs.
1360- // In case of errors it may be that typed trees point to untyped ones.
1361- // The IDE can still traverse inside such trees, either in the run where errors
1362- // are reported, or in subsequent ones.
1363- x
1385+ case _ =>
1386+ foldMoreCases(x, tree)
13641387 }
13651388 }
1389+
1390+ def foldMoreCases (x : X , tree : Tree )(implicit ctx : Context ): X = tree match {
1391+ case tpd.UntypedSplice (usplice) =>
1392+ // For a typed tree accumulator: skip the untyped part and fold all typed splices.
1393+ // The case is overridden in UntypedTreeAccumulator.
1394+ val untpdAcc = new untpd.UntypedTreeAccumulator [X ] {
1395+ override def apply (x : X , tree : untpd.Tree )(implicit ctx : Context ): X = tree match {
1396+ case untpd.TypedSplice (tsplice) => self(x, tsplice)
1397+ case _ => foldOver(x, tree)
1398+ }
1399+ }
1400+ untpdAcc(x, usplice)
1401+ case _ if ctx.reporter.errorsReported || ctx.mode.is(Mode .Interactive ) =>
1402+ // In interactive mode, errors might come from previous runs.
1403+ // In case of errors it may be that typed trees point to untyped ones.
1404+ // The IDE can still traverse inside such trees, either in the run where errors
1405+ // are reported, or in subsequent ones.
1406+ x
1407+ }
13661408 }
13671409
13681410 abstract class TreeTraverser extends TreeAccumulator [Unit ] {
0 commit comments