Skip to content

this.synchronized block prevents @tailrec check from passing #14308

@liosedhel

Description

@liosedhel

Compiler version

scala 3.1.2-RC1-bin-20220118-9e14f5f-NIGHTLY

Minimized code

import scala.annotation.tailrec

class TailrecProblem {
  @tailrec
  private def create(x: Int): Unit = {
    this.synchronized {
      if (x == 0) ()
      else create(x - 1)
    }
  }
}

Output

[error] -- Error: TailrecProblem.scala:8:17 
[error] 8 |      else create(x - 1)
[error]   |           ^^^^^^^^^^^^^
[error]   |           Cannot rewrite recursive call: it is not in tail position
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

Expectation

It compiles with scala 2.13.7, it does not with 3.1.2-RC1-bin-20220118-9e14f5f-NIGHTLY. Is it a regression or a change in behaviour and synchronized blocks tailrec invocation?

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