Open
Description
I'm following the example with AOP style mixin composition stacks using compound types, and it looks like if the apply()
method is used then it fails with stack overflow. It works with everything else.
So following the link http://jonasboner.com/aop-style-mixin-composition-stacks-in-scala/ everything works fine
// WORKS!
trait Stuff {
def doStuff(): Unit
}
class RealStuff extends Stuff {
def doStuff(): Unit = println("doing real stuff")
}
trait LoggableStuff extends Stuff {
abstract override def doStuff(): Unit = {
println("logging enter")
super.doStuff
println("logging exit")
}
}
val stuff = new RealStuff with LoggableStuff
stuff.doStuff()
However if I change the base trait to Function0[Unit]
it fails with stack overflow.
class RealFunction extends Function0[Unit] {
def apply(): Unit = println("doing real stuff")
}
trait LoggableFunction extends Function0[Unit] {
abstract override def apply(): Unit = {
println("logging enter")
super.apply()
println("logging exit")
}
}
val fn = new RealFunction with LoggableFunction
fn.apply()
But copying Function0
and taking out the @specialized
annotation makes it work:
// trait Function0[@specialized(Specializable.Primitives) +R] extends AnyRef { self =>
trait DerpFunction0[+R] extends AnyRef { self =>
/** Apply the body of this function to the arguments.
* @return the result of function application.
*/
def apply(): R
override def toString() = "<function0>"
}
class RealFunction extends DerpFunction0[Unit] {
def apply(): Unit = println("doing real stuff")
}
trait LoggableFunction extends DerpFunction0[Unit] {
abstract override def apply(): Unit = {
println("logging enter")
super.apply()
println("logging exit")
}
}
val fn = new RealFunction with LoggableFunction
fn.apply()
I think this is a bug, as there's nothing in documentation saying compound types work unless you have a type parameter with a @specialized
annotation.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Compound Types fail mysteriously with @specialized(Specializable.Primitives) [/-][+]Compound Types using @specialized(Specializable.Primitives) type parameter fail with stackoverflow[/+][-]Compound Types using @specialized(Specializable.Primitives) type parameter fail with stackoverflow[/-][+]Compound Types using @specialized type parameter fail with stackoverflow[/+]