Skip to content

@tailrec doesn't work on vals and no warning is raised #8742

Open
@scabug

Description

@scabug

Consider the following code

@tailrec
val gcd: (Int, Int) => Int = {
  case (a,b) if (a == b) => a
  case (a,b) if (a > b) => gcd (a-b,b)
  case (a,b) if (b > a) => gcd (a, b-a)
}

Expected result: either the gcd function is optimized into a loop or the compiler warns about @tailrec not being applied on vals

Actual result: the function is not optimized and no warning is raised by the compiler

This is confusing and it should be made explicit somehow. See http://stackoverflow.com/questions/24892624/how-to-ensure-tail-recursion-consistently for an example of unexpected behavior.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions