Skip to content

Commit f04f8db

Browse files
committed
TreeMap/TreeAccumulator: proper context for inlined trees
This was already be done in TreeTraverser but should also be done in TreeMap and TreeAccumulator for ctx.error(..., tree.pos) to not use completely incorrect positions inside inlined trees.
1 parent b297832 commit f04f8db

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,13 @@ object Trees {
10771077
/** Hook to indicate that a transform of some subtree should be skipped */
10781078
protected def skipTransform(tree: Tree)(implicit ctx: Context): Boolean = false
10791079

1080+
/** For untyped trees, this is just the identity.
1081+
* For typed trees, a context derived form `ctx` that records `call` as the
1082+
* innermost enclosing call for which the inlined version is currently
1083+
* processed.
1084+
*/
1085+
protected def inlineContext(call: Tree)(implicit ctx: Context): Context = ctx
1086+
10801087
abstract class TreeMap(val cpy: TreeCopier = inst.cpy) {
10811088

10821089
def transform(tree: Tree)(implicit ctx: Context): Tree =
@@ -1121,7 +1128,7 @@ object Trees {
11211128
case SeqLiteral(elems, elemtpt) =>
11221129
cpy.SeqLiteral(tree)(transform(elems), transform(elemtpt))
11231130
case Inlined(call, bindings, expansion) =>
1124-
cpy.Inlined(tree)(call, transformSub(bindings), transform(expansion))
1131+
cpy.Inlined(tree)(call, transformSub(bindings), transform(expansion)(inlineContext(call)))
11251132
case TypeTree() =>
11261133
tree
11271134
case SingletonTypeTree(ref) =>
@@ -1225,7 +1232,7 @@ object Trees {
12251232
case SeqLiteral(elems, elemtpt) =>
12261233
this(this(x, elems), elemtpt)
12271234
case Inlined(call, bindings, expansion) =>
1228-
this(this(x, bindings), expansion)
1235+
this(this(x, bindings), expansion)(inlineContext(call))
12291236
case TypeTree() =>
12301237
x
12311238
case SingletonTypeTree(ref) =>

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,10 +933,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
933933
/** A key to be used in a context property that tracks enclosing inlined calls */
934934
private val InlinedCalls = new Property.Key[List[Tree]]
935935

936-
/** A context derived form `ctx` that records `call` as innermost enclosing
937-
* call for which the inlined version is currently processed.
938-
*/
939-
def inlineContext(call: Tree)(implicit ctx: Context): Context =
936+
override def inlineContext(call: Tree)(implicit ctx: Context): Context =
940937
ctx.fresh.setProperty(InlinedCalls, call :: enclosingInlineds)
941938

942939
/** All enclosing calls that are currently inlined, from innermost to outermost */

0 commit comments

Comments
 (0)