Skip to content

Tailrec jammed by safer exceptions #17147

Closed
@abgruszecki

Description

@abgruszecki

Compiler version

$head -1 build.sbt 
ThisBuild / scalaVersion := "3.3.1-RC1-bin-20230322-1f574e8-NIGHTLY"

Minimized code

object TestyFactorial:
  // minimal example
  import scala.annotation.tailrec
  import language.experimental.saferExceptions

  @tailrec
  final def fact(n: Int, acc: Int): Int throws Exception =
    if n < 0 then
      throw new Exception
    else if n == 0 then
      acc
    else
      fact(n - 1, acc * n)

Output

$sbt clean compile
  ...
[error]  |    fact(n - 1, acc * n)
[error]  |    ^^^^^^^^^^^^^^^^^^^^
[error]  |    Cannot rewrite recursive call: it is not in tail position

Metadata

Metadata

Assignees

Labels

SpreeSuitable for a future Spreearea:saferExceptionsscala.language.experimental.saferExceptionsitype:bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions