@@ -589,6 +589,7 @@ object Trees {
589
589
case class Inlined [- T >: Untyped ] private [ast] (call : tpd.Tree , bindings : List [MemberDef [T ]], expansion : Tree [T ])
590
590
extends Tree [T ] {
591
591
type ThisTree [- T >: Untyped ] = Inlined [T ]
592
+ override def initialPos = call.pos
592
593
}
593
594
594
595
/** A type tree that represents an existing or inferred type */
@@ -922,6 +923,11 @@ object Trees {
922
923
case ys => Thicket (ys)
923
924
}
924
925
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
+ }
925
931
// ----- Helper classes for copying, transforming, accumulating -----------------
926
932
927
933
val cpy : TreeCopier
@@ -1109,6 +1115,10 @@ object Trees {
1109
1115
case tree : Annotated if (arg eq tree.arg) && (annot eq tree.annot) => tree
1110
1116
case _ => finalize(tree, untpd.Annotated (arg, annot))
1111
1117
}
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
+ }
1112
1122
def Thicket (tree : Tree )(trees : List [Tree ]): Thicket = tree match {
1113
1123
case tree : Thicket if trees eq tree.trees => tree
1114
1124
case _ => finalize(tree, untpd.Thicket (trees))
@@ -1146,7 +1156,7 @@ object Trees {
1146
1156
*/
1147
1157
protected def inlineContext (call : Tree )(implicit ctx : Context ): Context = ctx
1148
1158
1149
- abstract class TreeMap (val cpy : TreeCopier = inst.cpy) {
1159
+ abstract class TreeMap (val cpy : TreeCopier = inst.cpy) { self =>
1150
1160
1151
1161
def transform (tree : Tree )(implicit ctx : Context ): Tree = {
1152
1162
Stats .record(s " TreeMap.transform $getClass" )
@@ -1245,8 +1255,8 @@ object Trees {
1245
1255
case Thicket (trees) =>
1246
1256
val trees1 = transform(trees)
1247
1257
if (trees1 eq trees) tree else Thicket (trees1)
1248
- case _ if ctx.reporter.errorsReported =>
1249
- tree
1258
+ case _ =>
1259
+ transformMoreCases( tree)
1250
1260
}
1251
1261
}
1252
1262
@@ -1258,9 +1268,26 @@ object Trees {
1258
1268
transform(tree).asInstanceOf [Tr ]
1259
1269
def transformSub [Tr <: Tree ](trees : List [Tr ])(implicit ctx : Context ): List [Tr ] =
1260
1270
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
+ }
1261
1288
}
1262
1289
1263
- abstract class TreeAccumulator [X ] {
1290
+ abstract class TreeAccumulator [X ] { self =>
1264
1291
// Ties the knot of the traversal: call `foldOver(x, tree))` to dive in the `tree` node.
1265
1292
def apply (x : X , tree : Tree )(implicit ctx : Context ): X
1266
1293
@@ -1355,14 +1382,29 @@ object Trees {
1355
1382
this (this (x, arg), annot)
1356
1383
case Thicket (ts) =>
1357
1384
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)
1364
1387
}
1365
1388
}
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
+ }
1366
1408
}
1367
1409
1368
1410
abstract class TreeTraverser extends TreeAccumulator [Unit ] {
0 commit comments