Skip to content

Unable to call recursive private inline method defined in a trait #11706

Closed
@julienrf

Description

@julienrf

Compiler version

3.0.0

Minimized code

package bugreport

import scala.compiletime.erasedValue

object Obj:
  
  inline def length[Tuple]: Int = loop[Tuple]

  private inline def loop[Tuple]: Int =
    inline erasedValue[Tuple] match
      case _: EmptyTuple => 0
      case _: (head *: tail) => 1 + loop[tail]

end Obj

// Same code, but in a trait instead of an object
trait Trait:

  inline def length[Tuple]: Int = loop[Tuple]

  private inline final def loop[Tuple]: Int =
    inline erasedValue[Tuple] match
      case _: EmptyTuple => 0
      case _: (head *: tail) => 1 + loop[tail]

end Trait

@main def run() =
  println(Obj.length[(Int, Int, String)]) // OK
  new Trait:
    println(length[(Int, Int, String)]) // ERROR

Output

[error] -- Error: bugreport.scala:18:38 
[error] 18 |  inline def length[Tuple]: Int = loop[Tuple]
[error]    |                                  ^^^^^^^^^^^
[error]    |undefined: Trait_this.loop # -1: TermRef(TermRef(NoPrefix,val Trait_this),loop) at inlining

When I call the variant in the trait, I get this error. But the same code works fine with an object.

Expectation

Both versions work.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions