Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing @tailrec error with recusive call targeting supertype #11442

Open
smarter opened this Issue Mar 20, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@smarter
Copy link

commented Mar 20, 2019

The following outputs an error as expected:

import scala.annotation.tailrec

trait Outer { self =>
  def hi(cond: Boolean): Boolean

  trait Inner extends Outer {
    @tailrec
    final def hi(cond: Boolean): Boolean =
      self.hi(cond)
  }
}
try/super.scala:9: error: could not optimize @tailrec annotated method hi: it contains a recursive call targeting a supertype
      self.hi(cond)
           ^
one error found

The following also outputs an error:

import scala.annotation.tailrec

trait Outer { self =>
  def hi(cond: Boolean): Boolean

  trait Inner extends Outer {
    @tailrec
    final def hi(cond: Boolean): Boolean =
      self.hi(cond) && cond
  }
}
try/super.scala:8: error: could not optimize @tailrec annotated method hi: it contains a recursive call not in tail position
    final def hi(cond: Boolean): Boolean =
              ^
one error found

But this compiles without error:

import scala.annotation.tailrec

trait Outer { self =>
  def hi(cond: Boolean): Boolean

  trait Inner extends Outer {
    @tailrec
    final def hi(cond: Boolean): Boolean =
      self.hi(cond) && hi(cond)
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.