diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2017-02-13 04:04:21 +0100 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2017-02-13 23:42:18 +0100 |
commit | f04f8db9143dab8960d4577974856ee9a62d5909 (patch) | |
tree | d9ef9e9321bbdba3949ea3b83de8f56b43de1014 /compiler | |
parent | b29783237c03ade1dd19cc564170c7a87d7b8b84 (diff) | |
download | dotty-f04f8db9143dab8960d4577974856ee9a62d5909.tar.gz dotty-f04f8db9143dab8960d4577974856ee9a62d5909.tar.bz2 dotty-f04f8db9143dab8960d4577974856ee9a62d5909.zip |
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.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/src/dotty/tools/dotc/ast/Trees.scala | 11 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/ast/tpd.scala | 5 |
2 files changed, 10 insertions, 6 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index bf11a442e..27be8c9d6 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -1077,6 +1077,13 @@ object Trees { /** Hook to indicate that a transform of some subtree should be skipped */ protected def skipTransform(tree: Tree)(implicit ctx: Context): Boolean = false + /** For untyped trees, this is just the identity. + * For typed trees, a context derived form `ctx` that records `call` as the + * innermost enclosing call for which the inlined version is currently + * processed. + */ + protected def inlineContext(call: Tree)(implicit ctx: Context): Context = ctx + abstract class TreeMap(val cpy: TreeCopier = inst.cpy) { def transform(tree: Tree)(implicit ctx: Context): Tree = @@ -1121,7 +1128,7 @@ object Trees { case SeqLiteral(elems, elemtpt) => cpy.SeqLiteral(tree)(transform(elems), transform(elemtpt)) case Inlined(call, bindings, expansion) => - cpy.Inlined(tree)(call, transformSub(bindings), transform(expansion)) + cpy.Inlined(tree)(call, transformSub(bindings), transform(expansion)(inlineContext(call))) case TypeTree() => tree case SingletonTypeTree(ref) => @@ -1225,7 +1232,7 @@ object Trees { case SeqLiteral(elems, elemtpt) => this(this(x, elems), elemtpt) case Inlined(call, bindings, expansion) => - this(this(x, bindings), expansion) + this(this(x, bindings), expansion)(inlineContext(call)) case TypeTree() => x case SingletonTypeTree(ref) => diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index ed268fda7..d1d886c55 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -933,10 +933,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { /** A key to be used in a context property that tracks enclosing inlined calls */ private val InlinedCalls = new Property.Key[List[Tree]] - /** A context derived form `ctx` that records `call` as innermost enclosing - * call for which the inlined version is currently processed. - */ - def inlineContext(call: Tree)(implicit ctx: Context): Context = + override def inlineContext(call: Tree)(implicit ctx: Context): Context = ctx.fresh.setProperty(InlinedCalls, call :: enclosingInlineds) /** All enclosing calls that are currently inlined, from innermost to outermost */ |