File tree Expand file tree Collapse file tree 3 files changed +24
-10
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -603,7 +603,7 @@ object Erasure {
603603 if (tree.typeOpt.isRef(defn.UnitClass ))
604604 tree.withType(tree.typeOpt)
605605 else if (tree.const.tag == Constants .ClazzTag )
606- clsOf(tree.const.typeValue)
606+ clsOf(tree.const.typeValue).withSpan(tree.span)
607607 else
608608 super .typedLiteral(tree)
609609
@@ -739,6 +739,23 @@ object Erasure {
739739 checkValue(checkNotErased(recur(qual1)), pt)
740740 }
741741
742+ // TODO track in a cleaner way
743+ private var enclosingSpan : util.Spans .Span = util.Spans .NoSpan
744+
745+ override def typed (tree : untpd.Tree , pt : Type , locked : TypeVars )(using Context ): Tree =
746+ val old = enclosingSpan
747+ enclosingSpan = tree.span
748+ val tree1 =
749+ try super .typed(tree, pt, locked)
750+ finally enclosingSpan = old
751+
752+ if tree1.source.exists && ctx.source != tree1.source && ctx.source == ctx.owner.topLevelClass.source
753+ then
754+ // TODO reposition while erasing instead of retraversing
755+ Inliner .reposition(tree1, enclosingSpan)
756+ else tree1
757+
758+
742759 override def typedThis (tree : untpd.This )(using Context ): Tree =
743760 if (tree.symbol == ctx.owner.lexicallyEnclosingClass || tree.symbol.isStaticOwner) promote(tree)
744761 else {
Original file line number Diff line number Diff line change @@ -207,16 +207,13 @@ object Inliner {
207207
208208 /** Replace `Inlined` node by a block that contains its bindings and expansion */
209209 def dropInlined (inlined : Inlined )(using Context ): Tree =
210- val tree1 =
211- if inlined.bindings.isEmpty then inlined.expansion
212- else cpy.Block (inlined)(inlined.bindings, inlined.expansion)
213- // Reposition in the outer most inlined call
214- if (enclosingInlineds.nonEmpty) tree1 else reposition(tree1, inlined.span)
210+ if inlined.bindings.isEmpty then inlined.expansion
211+ else cpy.Block (inlined)(inlined.bindings, inlined.expansion)
215212
216213 def reposition (tree : Tree , callSpan : Span )(using Context ): Tree = {
217214 // Reference test tests/run/i4947b
218215
219- val curSource = ctx.compilationUnit .source
216+ val curSource = ctx.owner.topLevelClass .source
220217
221218 // Tree copier that changes the source of all trees to `curSource`
222219 val cpyWithNewSource = new TypedTreeCopier {
Original file line number Diff line number Diff line change 1- assertImpl: Test$.main(Test_2.scala:7 )
1+ assertImpl: Test$.main(Test_2.scala:3 )
22true
3- assertImpl: Test$.main(Test_2.scala:8 )
3+ assertImpl: Test$.main(Test_2.scala:3 )
44false
5- assertImpl: Test$.main(Test_2.scala:9 )
5+ assertImpl: Test$.main(Test_2.scala:3 )
66hi: Test$.main(Test_2.scala:10)
77hi again: Test$.main(Test_2.scala:11)
88false
You can’t perform that action at this time.
0 commit comments