Skip to content

Missing @tailrec error with recursive call targeting supertype #11442

Open
@smarter

Description

@smarter

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)
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions