Skip to content

Commit 677906b

Browse files
sjrdWojciechMazur
authored andcommitted
Fix #18816: Transfer the span of rewired This nodes in fullyParameterizedDef.
[Cherry-picked f214f05]
1 parent c91d22c commit 677906b

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

compiler/src/dotty/tools/dotc/transform/FullParameterization.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ trait FullParameterization {
206206
.subst(origLeadingTypeParamSyms ++ origOtherParamSyms, (trefs ++ argRefs).tpes)
207207
.substThisUnlessStatic(origClass, thisRef.tpe),
208208
treeMap = {
209-
case tree: This if tree.symbol == origClass => thisRef
209+
case tree: This if tree.symbol == origClass => thisRef.withSpan(tree.span)
210210
case tree => rewireTree(tree, Nil) orElse tree
211211
},
212212
oldOwners = origMeth :: Nil,

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala

+32
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,38 @@ class DottyBytecodeTests extends DottyBytecodeTest {
17011701

17021702
}
17031703
}
1704+
1705+
@Test def i18816 = {
1706+
// The primary goal of this test is to check that `LineNumber` have correct numbers
1707+
val source =
1708+
"""trait Context
1709+
|
1710+
|class A(x: Context) extends AnyVal:
1711+
| given [T]: Context = x
1712+
|
1713+
| def m1 =
1714+
| println(m3)
1715+
| def m2 =
1716+
| m3 // line 9
1717+
| println(m2)
1718+
|
1719+
| def m3(using Context): String = ""
1720+
""".stripMargin
1721+
1722+
checkBCode(source) { dir =>
1723+
val clsIn = dir.lookupName("A$.class", directory = false).input
1724+
val clsNode = loadClassNode(clsIn, skipDebugInfo = false)
1725+
val method = getMethod(clsNode, "m2$1")
1726+
val instructions = instructionsFromMethod(method).filter(_.isInstanceOf[LineNumber])
1727+
1728+
// There used to be references to line 7 here
1729+
val expected = List(
1730+
LineNumber(9, Label(0)),
1731+
)
1732+
1733+
assertSameCode(instructions, expected)
1734+
}
1735+
}
17041736
}
17051737

17061738
object invocationReceiversTestCode {

0 commit comments

Comments
 (0)