Hi,
with Scala 2.10.0-RC1 I found an issue with stackable traits that
doesn't come up with Scala 2.9.2. Based on trait X
trait X { def foo: PartialFunction[Int, Int] }
and two stackable traits Y and Z (that extend X):
trait Y extends X { abstract override def foo = { case i => super.foo(i)
* 2 } }
trait Z extends X { abstract override def foo = { case i => super.foo(i)
+ 3 } }
I have another stackable trait Comb that combines what Y and Z are doing
(and that does some additional work):
trait Comb extends Y with Z { abstract override def foo:
PartialFunction[Int, Int] = { case i => super.foo(i) - 2 } }
This compiles with Scala 2.9.2 without problems but with Scala
2.10.0-RC1 I'm getting the following error:
[error] ...: missing parameter type for expanded function
[error] The argument types of an anonymous function must be fully known.
(SLS 8.5)
[error] Expected type was:
scala.runtime.AbstractPartialFunction[Int,Int] with Serializable
[error] trait Comb extends Y with Z { abstract override def foo = {
case i => super.foo(i) - 2 } }
[error] ^
[error] one error found
Of course I can get around this issue by writing the foo method type
explicitly
trait Y extends X { abstract override def foo: PartialFunction[Int, Int]
= { case i => super.foo(i) * 2 } }
trait Z extends X { abstract override def foo: PartialFunction[Int, Int]
= { case i => super.foo(i) + 3 } }
trait Comb extends Y with Z { abstract override def foo:
PartialFunction[Int, Int] = { case i => super.foo(i) - 2 } }
but then any concrete class that should be modified with Comb must add
the foo method type as well i.e.
class Temp extends X { def foo: PartialFunction[Int, Int] = { case i =>
i } }
val tmp = new Temp with Comb
// ...
which wasn't necessary with Scala 2.9.2 either. If the type is omitted i.e.
class Temp extends X { def foo = { case i => i } }
val tmp = new Temp with Comb
// ...
I'm getting
[error] ...: overriding method foo in class Temp of type =>
scala.runtime.AbstractPartialFunction[Int,Int] with Serializable;
[error] method foo in trait Comb of type => PartialFunction[Int,Int]
has incompatible type
[error] val tmp2 = new Temp with Comb
[error] ^
[error] one error found
Any ideas?
Thanks,
Martin
--
Martin Krasser
blog:
http://krasserm.blogspot.com
code:
http://github.com/krasserm
twitter:
http://twitter.com/mrt1nz