@tailrec not correctly supported in main object #122

Open
skyluc opened this Issue Apr 2, 2013 · 2 comments

Comments

Projects
None yet
1 participant
@skyluc
Member

skyluc commented Apr 2, 2013

An error is reported the level of the @tailrec, when using it at a top level def, in the main object of a worksheet:

import scala.annotation.tailrec
object worksheet {
  @tailrec
  def f(i: Int): Int =
    if (i % 2 == 0)
      i
    else
      f(i -1)
}

The reason is that the annotation is not correctly managed by the instrumentation. The code generated is the following:

 @tailrec;$skip(87);
  def f(i: Int): Int =
    if (i % 2 == 0)
...

And it looks like there will be another problem when this is fixed, the worksheet doesn't allow the use of private or final on a top level def, which is required to be able to use @tailrec.

The workaround is to put the @tailrec inside a def, or in a different object.

@skyluc

This comment has been minimized.

Show comment
Hide comment
@skyluc

skyluc Apr 2, 2013

Member

Originally reported against Scala IDE: #1001636.

Member

skyluc commented Apr 2, 2013

Originally reported against Scala IDE: #1001636.

@skyluc

This comment has been minimized.

Show comment
Hide comment
@skyluc

skyluc Apr 3, 2013

Member

My comment on a possible additionnal problem is wrong. private or final modifier cannot be used at this position, but it doesn't block using @tailrec if the code is correctly instrumented.

Member

skyluc commented Apr 3, 2013

My comment on a possible additionnal problem is wrong. private or final modifier cannot be used at this position, but it doesn't block using @tailrec if the code is correctly instrumented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment