Skip to content

Commit

Permalink
Fix #18816: Transfer the span of rewired This nodes in `fullyParame…
Browse files Browse the repository at this point in the history
…terizedDef`. (#18840)
  • Loading branch information
sjrd committed Nov 6, 2023
2 parents 82d22c6 + f214f05 commit eb7fbff
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 @@ -207,7 +207,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 eb7fbff

Please sign in to comment.