Issue with stackable traits and Scala 2.10.0-RC1

58 views
Skip to first unread message

Martin Krasser

unread,
Oct 28, 2012, 7:33:03 AM10/28/12
to scala...@googlegroups.com
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

Jason Zaugg

unread,
Oct 28, 2012, 7:53:47 AM10/28/12
to Martin Krasser, scala...@googlegroups.com
That's an implementation detail leaking into your inferred types. It
looks straight forward to fix; please open a ticket.

-jason

Martin Krasser

unread,
Oct 28, 2012, 8:12:56 AM10/28/12
to scala...@googlegroups.com
Hi Jason,

thanks for the quick response. The ticket is at
https://issues.scala-lang.org/browse/SI-6575.

Cheers,
Martin

Am 28.10.12 12:53, schrieb Jason Zaugg:
Reply all
Reply to author
Forward
0 new messages