diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-07-22 09:50:04 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-07-22 09:59:25 +1000 |
commit | 04649c74c47af1b6e21648e4dfe7db0417f3a9ba (patch) | |
tree | 555f182a49057890cfd7c89ff1e816b5f66b8fb6 /test | |
parent | 4e564efb04e508ccc0f479cf1a25331501927d88 (diff) | |
download | scala-04649c74c47af1b6e21648e4dfe7db0417f3a9ba.tar.gz scala-04649c74c47af1b6e21648e4dfe7db0417f3a9ba.tar.bz2 scala-04649c74c47af1b6e21648e4dfe7db0417f3a9ba.zip |
SD-186 Fix positions in trait method bytecode
Concrete, non private methods in traits are translated into a static
method with an explicit `$this` parameter. After this translation,
the references to `$this` (subistuted for `this` in user written code)
where being positioned at the position of the method, which makes
debugging unpleasant.
This commit leaves the `Ident($this)` trees unpositioned. This is
analagous to what we do in the body of extension methods, which
is the other user of `ThisSubstitutor`.
It would be more correct to copy the position of each `This`
tree over to the substituted tree. That would let us set a breakpoint
on a line that _only_ contained `this`. But in 99% of cases users
won't be able to spot the difference, so I've opted for the tried
and tested approach here.
Diffstat (limited to 'test')
-rw-r--r-- | test/junit/scala/tools/nsc/backend/jvm/BytecodeTest.scala | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/backend/jvm/BytecodeTest.scala b/test/junit/scala/tools/nsc/backend/jvm/BytecodeTest.scala index b2ee8b3a45..5904cb2441 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/BytecodeTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/BytecodeTest.scala @@ -168,4 +168,23 @@ class BytecodeTest extends BytecodeTesting { assertEquals(x.start, labels(1)) assertEquals(x.end, labels(7)) } + + @Test // wrong line numbers for rewritten `this` references in trait static methods + def sd186_traitLineNumber(): Unit = { + val code = + """trait T { + | def t(): Unit = { + | toString + | toString + | } + |} + """.stripMargin + val t = compileClass(code) + val tMethod = getMethod(t, "t$") + val invoke = Invoke(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;", false) + assertSameCode(tMethod.instructions, + List(Label(0), LineNumber(3, Label(0)), VarOp(ALOAD, 0), invoke, Op(POP), + Label(5), LineNumber(4, Label(5)), VarOp(ALOAD, 0), invoke, Op(POP), Op(RETURN), Label(11)) + ) + } } |