code |
// tested with nightly build scala-2.5.1.12368.20070720-074545
object AbstractMethodErrorTest extends Application
{
def flattenWithSelf[T](self: T, deps: => List[T], recurse: T => List[T]): List[T] =
{
self :: deps.flatMap(recurse(_)).removeDuplicates
}
abstract class Module
{ self =>
final type commonModuleType = Module
protected def moduleDemands: List[Module]
final def moduleRequirementsWithSelf: List[commonModuleType] =
flattenWithSelf[Module](self, moduleDemands, _.moduleRequirementsWithSelf)
}
object FirstModule extends Module
{
def moduleDemands: List[Module] = Nil
}
object SecondModule extends Module
{
def moduleDemands: List[Module] = List(FirstModule)
}
assert(SecondModule.moduleRequirementsWithSelf == List(SecondModule, FirstModule))
}
/*
Exception in thread "main" java.lang.AbstractMethodError: AbstractMethodErrorTest$Module$$anonfun$2.apply(Ljava/lang/Object;)Ljava/lang/Object;
at AbstractMethodErrorTest$$anonfun$0.apply(AbstractMethodErrorTest.scala:8)
at AbstractMethodErrorTest$$anonfun$0.apply(AbstractMethodErrorTest.scala:8)
at scala.List.flatMap(List.scala:995)
at AbstractMethodErrorTest$.flattenWithSelf(AbstractMethodErrorTest.scala:8)
at AbstractMethodErrorTest$Module.moduleRequirementsWithSelf(AbstractMethodErrorTest.scala:18)
at AbstractMethodErrorTest$.<init>(AbstractMethodErrorTest.scala:31)
at AbstractMethodErrorTest$.<clinit>(AbstractMethodErrorTest.scala)
at AbstractMethodErrorTest.main(AbstractMethodErrorTest.scala)
Note that changing a return type gives successful execution:
// final def moduleRequirementsWithSelf: List[Module]
*/
|