class Specialized[@specialized A] {
def stackTrace(token :A) = new Exception().getStackTrace.toSeq
}
trait Mixin[@specialized A] extends Specialized[A] {
def trace(token :A) = stackTrace(token)
}
object I extends Specialized[Int] with Mixin[Int]
println(I.trace(0).mkString("", "\n", ""))
Problem
The compiler produces the following warnings:
/home/turin/porn/sugar/src/test/scala/Playground.scala:9:4
class Specialized must be a trait. Specialized version of trait Mixin will inherit generic Playground.Specialized[Int]
trait Mixin[@specialized(Int) A] extends Specialized[A] {
However, executing the code shows the following stack trace:
We can see that Mixin[Int].trace, when invoked, calls Specialized[Int].stackTrace directly, and of course I extends the specialized variant of Specialized, so this composition should be completely legal, as no functionality is lost.
Reproduction steps
Scala version: 2.13.11
Problem
The compiler produces the following warnings:
However, executing the code shows the following stack trace:
We can see that
Mixin[Int].trace
, when invoked, callsSpecialized[Int].stackTrace
directly, and of courseI
extends the specialized variant ofSpecialized
, so this composition should be completely legal, as no functionality is lost.