Skip to content

Unable to inline tailrec methods #4737

Closed
@allanrenucci

Description

@allanrenucci
import annotation.tailrec
class Test {
  @inline @tailrec def rec(x: Int): Int = {
    if (x > 0) rec(x - 1)
    else 0
  }

  def bar = rec(100)
}

fails to compile with Dotty

-- Error: tests/allan/Test.scala:25:18 -----------------------------------------
25 |    if (x > 0) rec(x - 1)
   |               ^^^^^^^^^^
   |               Maximal number of successive inlines (32) exceeded,
   |               Maybe this is caused by a recursive inline method?
   |               You can use -Xmax:inlines to change the limit.
   | This location is in code that was inlined at tests/allan/Test.scala:25

Scalac does not have this limitation because inlining happens after the tailrec optimisation.

I believe this change of behavior might break a lot of code, and we should turn the error into a warning.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions