Skip to content

Bytecode line numbers for calls within inlined code may be worng #6085

Open
@nicolasstucki

Description

@nicolasstucki

Currently the line numbers of method invocations in the bytecode uses the last parameter as the line of the call. This is useful to save an extra label and line number in the bytecode and avoid jumping back while debugging.

Unfortunately if the last argument happens to be inlined from somewhere else, the call also inherits this line number.

object Test {

  inline def fun[T](inline tag: String): Unit = {
    printStack(
      tag,
      "track" // line 6
    )
    printStack(
      "track",
      tag // line 10
    )
  }

  def printStack(tag1: String, tag2: String): Unit = {
    println(s"$tag1 $tag2: ${new Exception().getStackTrace().apply(1)}")
  }

  def main(args: Array[String]): Unit = {
    fun(
      "abc" // line 20
    )
  }
}
abc track: Test$.main(i4947a2.scala:6)
track abc: Test$.main(i4947a2.scala:20)

Note: this only hapend on top of #6066 which fixes the positions of inlined arguments with singleton types. Before the buggy position happend to negate it self with this bug.

Possible solutions:

  • Use the end line of the position of theApply/TypeApply as position of invocation
    • For every invocation: would increse bytecode size of every multiline call
    • Only if the position of the last argument if not contained in the position of the call
  • Loose all inline positions: we already have to do it for all inline code that comes from another file. The position of the call is used for all inlined trees.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions