Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken type inference with stackable traits #6575

Closed
scabug opened this issue Oct 28, 2012 · 4 comments
Closed

Broken type inference with stackable traits #6575

scabug opened this issue Oct 28, 2012 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Oct 28, 2012

(From at https://groups.google.com/d/topic/scala-user/2pcH-ck46Qg/discussion)

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 
@scabug
Copy link
Author

scabug commented Oct 28, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6575?orig=1
Reporter: Martin Krasser (krasserm)
Affected Versions: 2.10.0-RC1
Other Milestones: 2.10.0

@scabug
Copy link
Author

scabug commented Oct 28, 2012

@retronym said:
scala/scala#1528

@scabug
Copy link
Author

scabug commented Oct 29, 2012

@jsuereth said:
This appears to have no workaround.

@scabug
Copy link
Author

scabug commented Oct 30, 2012

@adriaanm said:
scala/scala#1530

@scabug scabug closed this as completed Oct 30, 2012
@scabug scabug added this to the 2.10.0-RC1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants