Skip to content

Cannot rewrite recursive call: it is not in tail position error #13941

Closed
@xuwei-k

Description

@xuwei-k

Compiler version

  • 3.1.2-RC1-bin-20211102-82172ed-NIGHTLY
  • 3.1.1-RC1
  • 3.1.0
  • 3.0.2

Minimized code

import scala.annotation.tailrec

class A {
  def b = Option("a").map { x =>
    @tailrec def loop(): Int = {
      try {
        2
      } catch { 
        case _: Throwable =>
          loop()
      }
    }
    x
  }
}

Output

[error] 10 |          loop()
[error]    |          ^^^^^^
[error]    |          Cannot rewrite recursive call: it is not in tail position

Expectation

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions