File tree 3 files changed +24
-10
lines changed
compiler/src/dotty/tools/dotc
3 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -603,7 +603,7 @@ object Erasure {
603
603
if (tree.typeOpt.isRef(defn.UnitClass ))
604
604
tree.withType(tree.typeOpt)
605
605
else if (tree.const.tag == Constants .ClazzTag )
606
- clsOf(tree.const.typeValue)
606
+ clsOf(tree.const.typeValue).withSpan(tree.span)
607
607
else
608
608
super .typedLiteral(tree)
609
609
@@ -739,6 +739,23 @@ object Erasure {
739
739
checkValue(checkNotErased(recur(qual1)), pt)
740
740
}
741
741
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
+
742
759
override def typedThis (tree : untpd.This )(using Context ): Tree =
743
760
if (tree.symbol == ctx.owner.lexicallyEnclosingClass || tree.symbol.isStaticOwner) promote(tree)
744
761
else {
Original file line number Diff line number Diff line change @@ -207,16 +207,13 @@ object Inliner {
207
207
208
208
/** Replace `Inlined` node by a block that contains its bindings and expansion */
209
209
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)
215
212
216
213
def reposition (tree : Tree , callSpan : Span )(using Context ): Tree = {
217
214
// Reference test tests/run/i4947b
218
215
219
- val curSource = ctx.compilationUnit .source
216
+ val curSource = ctx.owner.topLevelClass .source
220
217
221
218
// Tree copier that changes the source of all trees to `curSource`
222
219
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 )
2
2
true
3
- assertImpl: Test$.main(Test_2.scala:8 )
3
+ assertImpl: Test$.main(Test_2.scala:3 )
4
4
false
5
- assertImpl: Test$.main(Test_2.scala:9 )
5
+ assertImpl: Test$.main(Test_2.scala:3 )
6
6
hi: Test$.main(Test_2.scala:10)
7
7
hi again: Test$.main(Test_2.scala:11)
8
8
false
You can’t perform that action at this time.
0 commit comments