Skip to content

Tail recursion from inside value defs #20145

Closed
@LucySMartin

Description

@LucySMartin

Compiler version

3.4.1

Minimized code

import scala.annotation.tailrec
  @tailrec
  def foo(i: Int): Int = {
    if (i > 10000000) {
      i
    } else {
      val bar: String = {
        return foo(i + 1)
        "foo"
      }
      -1
    }
  }
println(foo(0))

Output

Stack overflow error on the line return foo(i + 1)

Expectation

10000001 should be prited to the console - or if it is determined this is not a tail location - it shoud fail to compile.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions