Skip to content

tailrec optimization of def's involving implicit functions #4196

Closed
@ghost

Description

The following example shows that implicit functions and tail recursion do not seem to get along very well

$ dotr
Starting dotty REPL...
scala> @annotation.tailrec def foo(i: Int): Int = if (i == 0) { 0 } else { foo(i - 1) } // ok  
def foo(i: Int): Int
scala> @annotation.tailrec def bar(i: implicit Unit => Int): implicit Unit => Int = if (i == 0) { 0 } else { bar(i - 1) } // ko 
1 |@annotation.tailrec def bar(i: implicit Unit => Int): implicit Unit => Int = if (i == 0) { 0 } else { bar(i - 1) } // ko
  |                        ^
  |            TailRec optimisation not applicable, method not tail recursive
scala>

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