Skip to content

Assignment as the final statement in a block emits an additional debug line/breakpoint #12835

@vasilmkd

Description

@vasilmkd

Reproduction steps

Scala 2.12.18 and Scala 2.13.11 (and also in Scala 3.3.0)

object main {
  def main(args: Array[String]): Unit = {
    val x = 123
  }
}

Problem

Compiled bytecode

Compiled from "main.scala"
public final class main$ {
  public static final main$ MODULE$;

  public static {};
    Code:
       0: new           #2                  // class main$
       3: dup
       4: invokespecial #12                 // Method "<init>":()V
       7: putstatic     #14                 // Field MODULE$:Lmain$;
      10: return
    LineNumberTable:
      line 1: 0

  public void main(java.lang.String[]);
    Code:
       0: bipush        123
       2: istore_2
       3: return
    LineNumberTable:
      line 3: 0
      line 4: 3                          <----------- this line is not necessary, line 4 is a closing bracket
    LocalVariableTable:
      Start  Length  Slot  Name   Signature
          3       1     2     x   I
          0       4     0  this   Lmain$;
          0       4     1  args   [Ljava/lang/String;

  private main$();
    Code:
       0: aload_0
       1: invokespecial #22                 // Method java/lang/Object."<init>":()V
       4: return
    LineNumberTable:
      line 1: 0
    LocalVariableTable:
      Start  Length  Slot  Name   Signature
          0       5     0  this   Lmain$;
}

Here's how this line manifests in the debugger. The behavior is the same in Metals.

Screen.Recording.2023-08-01.at.12.04.44.mov

Expectation

The debug information line 4 is not generated.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions