Skip to content

Commit

Permalink
Backport "Fix #18816: Transfer the span of rewired This nodes in `f…
Browse files Browse the repository at this point in the history
…ullyParameterizedDef`." to LTS (#20966)

Backports #18840 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jul 3, 2024
2 parents c470726 + 677906b commit 528f3b7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ trait FullParameterization {
.subst(origLeadingTypeParamSyms ++ origOtherParamSyms, (trefs ++ argRefs).tpes)
.substThisUnlessStatic(origClass, thisRef.tpe),
treeMap = {
case tree: This if tree.symbol == origClass => thisRef
case tree: This if tree.symbol == origClass => thisRef.withSpan(tree.span)
case tree => rewireTree(tree, Nil) orElse tree
},
oldOwners = origMeth :: Nil,
Expand Down
32 changes: 32 additions & 0 deletions compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,38 @@ class DottyBytecodeTests extends DottyBytecodeTest {

}
}

@Test def i18816 = {
// The primary goal of this test is to check that `LineNumber` have correct numbers
val source =
"""trait Context
|
|class A(x: Context) extends AnyVal:
| given [T]: Context = x
|
| def m1 =
| println(m3)
| def m2 =
| m3 // line 9
| println(m2)
|
| def m3(using Context): String = ""
""".stripMargin

checkBCode(source) { dir =>
val clsIn = dir.lookupName("A$.class", directory = false).input
val clsNode = loadClassNode(clsIn, skipDebugInfo = false)
val method = getMethod(clsNode, "m2$1")
val instructions = instructionsFromMethod(method).filter(_.isInstanceOf[LineNumber])

// There used to be references to line 7 here
val expected = List(
LineNumber(9, Label(0)),
)

assertSameCode(instructions, expected)
}
}
}

object invocationReceiversTestCode {
Expand Down

0 comments on commit 528f3b7

Please sign in to comment.