Skip to content

Inliner incorrectly modifies IINC on parameters #13156

@SolalPirelli

Description

@SolalPirelli

scala/scala@bfa1380#diff-6402881c68d306988091172b129869daad7519257b48d97d2632465789d7383a added handling for VarInsnNode at (new) line 744 of Inliner.scala but missed changing the IincInsnNode case just below.

Thus, IINC instructions aren't properly modified when their target is a parameter.

This was found while porting the optimizer to Scala 3, in which the following is a repro:

//> using options -opt-inline:**

object Test {
  def foo(b: Option[Int]): Unit =
    fooRec(x = 0, b)

  private def fooRec(x: Int, b: Option[Int]): Unit = {
    if (b.nonEmpty) {
      fooRec(x + 1, b)
    }
  }

  def main(args: Array[String]): Unit = {
    foo(None)
  }
}

I haven't actually tested it with scala2 but the underlying problem should also exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions