@@ -155,7 +155,7 @@ object Inliner {
155
155
if (enclosingInlineds.nonEmpty) inlined // Remove in the outer most inlined call
156
156
else reposition(inlined, inlined.call.span)
157
157
158
- def reposition (tree : Tree , span : Span )(implicit ctx : Context ): Tree = {
158
+ def reposition (tree : Tree , callSpan : Span )(implicit ctx : Context ): Tree = {
159
159
val curSource = ctx.compilationUnit.source
160
160
161
161
// Tree copier that changes the source of all trees to `curSource`
@@ -169,39 +169,31 @@ object Inliner {
169
169
/** Removes all Inlined trees, replacing them with blocks.
170
170
* Repositions all trees directly inside an inlined expansion of a non empty call to the position of the call.
171
171
* Any tree directly inside an empty call (inlined in the inlined code) retains their position.
172
+ *
173
+ * Until we implement JSR-45, we cannot represent in output positions in other source files.
174
+ * So, reposition inlined code from other files with the call position.
172
175
*/
173
176
class Reposition extends TreeMap (cpyWithNewSource) {
174
- def finalize (tree : Tree , copied : untpd.Tree ) =
175
- copied.withSpan(tree.span).withAttachmentsFrom(tree).withTypeUnchecked(tree.tpe)
176
-
177
- def reposition (tree : Tree )(implicit ctx : Context ): Tree = enclosingInlineds match {
178
- case call :: _ if call.symbol.source != curSource =>
179
- tree match {
180
- case _ : EmptyTree [? ] | _ : EmptyValDef [? ] => tree
181
- case _ =>
182
- // Until we implement JSR-45, we cannot represent in output positions in other source files.
183
- // So, reposition inlined code from other files with the call position:
184
- tree.withSpan(span)
185
- }
186
- case _ => tree
187
- }
188
177
189
178
override def transform (tree : Tree )(implicit ctx : Context ): Tree = {
190
- val transformed = reposition(tree match {
191
- case tree : Inlined =>
192
- tpd.seq(transformSub(tree.bindings), transform(tree.expansion)(inlineContext(tree.call)))(ctx.withSource(curSource)) : Tree
193
- case tree : Ident => finalize(tree, untpd.Ident (tree.name)(curSource))
194
- case tree : Literal => finalize(tree, untpd.Literal (tree.const)(curSource))
195
- case tree : This => finalize(tree, untpd.This (tree.qual)(curSource))
196
- case tree : JavaSeqLiteral => finalize(tree, untpd.JavaSeqLiteral (transform(tree.elems), transform(tree.elemtpt))(curSource))
197
- case tree : SeqLiteral => finalize(tree, untpd.SeqLiteral (transform(tree.elems), transform(tree.elemtpt))(curSource))
198
- case tree : TypeTree => tpd.TypeTree (tree.tpe)(ctx.withSource(curSource)).withSpan(tree.span)
199
- case tree : Bind => finalize(tree, untpd.Bind (tree.name, transform(tree.body))(curSource))
179
+ def finalize (copied : untpd.Tree ) =
180
+ val span = if tree.source == curSource then tree.span else callSpan
181
+ copied.withSpan(span).withAttachmentsFrom(tree).withTypeUnchecked(tree.tpe)
182
+
183
+ given as Context = ctx.withSource(curSource)
184
+
185
+ tree match {
186
+ case tree : Inlined => transform(seq(tree.bindings, tree.expansion).withSpan(tree.span)) // remove Inlined by making them blocks
187
+ case tree : Ident => finalize(untpd.Ident (tree.name)(curSource))
188
+ case tree : Literal => finalize(untpd.Literal (tree.const)(curSource))
189
+ case tree : This => finalize(untpd.This (tree.qual)(curSource))
190
+ case tree : JavaSeqLiteral => finalize(untpd.JavaSeqLiteral (transform(tree.elems), transform(tree.elemtpt))(curSource))
191
+ case tree : SeqLiteral => finalize(untpd.SeqLiteral (transform(tree.elems), transform(tree.elemtpt))(curSource))
192
+ case tree : Bind => finalize(untpd.Bind (tree.name, transform(tree.body))(curSource))
193
+ case tree : TypeTree => finalize(tpd.TypeTree (tree.tpe))
200
194
case tree : DefTree => super .transform(tree).setDefTree
201
195
case _ => super .transform(tree)
202
- })
203
- assert(transformed.isInstanceOf [EmptyTree [? ]] || transformed.isInstanceOf [EmptyValDef [? ]] || transformed.source == curSource)
204
- transformed
196
+ }
205
197
}
206
198
}
207
199
0 commit comments