From 677906bc9fc6ea3d304b4ce35bb1fd7899423f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Fri, 3 Nov 2023 17:08:19 +0100 Subject: [PATCH] Fix #18816: Transfer the span of rewired `This` nodes in `fullyParameterizedDef`. [Cherry-picked f214f057e0c7202e5857b5ef0459b29120700ed2] --- .../dotc/transform/FullParameterization.scala | 2 +- .../backend/jvm/DottyBytecodeTests.scala | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala b/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala index 5fa85f8ad7b0..dbb4c72ab311 100644 --- a/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala +++ b/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala @@ -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, diff --git a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala index 29119c8d081f..5b7e737d419a 100644 --- a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala +++ b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala @@ -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 {