Skip to content
This repository was archived by the owner on Jun 5, 2023. It is now read-only.
This repository was archived by the owner on Jun 5, 2023. It is now read-only.

Allow tail calls after return statements #261

@mbovel

Description

@mbovel

Minimal example

  @annotation.tailrec
  def sum(n: Int, acc: Int): Int =
    if n != 0 then return sum(n - 1, n + acc)
    acc

fails:

3 |    if n != 0 then return sum(n - 1, n + acc)
  |                          ^^^^^^^^^^^^^^^^^^^
  |                 Cannot rewrite recursive call: it is not in tail position

Rational

Early-returns are useful to avoid nesting conditions. For example, this would be better written with early returns.

Note: this might be a nice issue for a spree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SpreeSuitable for a spree

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions