What are the limitations of extending a trait with constructor?

here is a quick example:


  trait A(delegate: Any = this) // this won't work in Scala 2.13

  object A1 extends A(A1)

  trait B extends A(A1) // still doensn't work
/*
trait B may not call constructor of trait A
  trait B extends A(A1)
*/

The documentation is here:

https://docs.scala-lang.org/scala3/reference/other-new-features/trait-parameters.html

And it links to the SIP which has some limitations:

https://docs.scala-lang.org/sips/trait-parameters.html#restrictions

Including traits not being able to instantiate trait arguments.
As for reasoning, my guess is this both simplifies the implementation, but also removes the potential cases where a parameter is specified (which is good given the complexity of figuring out which definition is used in a complex class hierarchy)

1 Like