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

Spurious error about incompatible type signatures when override Iterable.filter #1163

Closed
scabug opened this issue Aug 2, 2008 · 6 comments
Closed
Assignees

Comments

@scabug
Copy link

scabug commented Aug 2, 2008

I've attached a code sample which fails to compile. In it I override filter on Iterable with an abstract definition claiming to return a subtype of Iterable. This fails to compile with the error message

error overriding method filter;
 method filter in trait Iterable of type (((T, T)) => Boolean)Iterable[(T, T)] has incompatible type ((A) => Boolean)Iterable[A]
trait Foo[T] extends Iterable[(T, T)]{

However, the second two traits defined in this file exhibit the same overriding pattern and work fine. Additionally, if I add an implementation (say = error("foo")) to the definition of filter in Foo, the type error goes away.

@scabug
Copy link
Author

scabug commented Aug 2, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1163?orig=1
Reporter: @DRMacIver
Attachments:

  • filter.scala (created on Aug 2, 2008 2:37:29 PM UTC, 252 bytes)
  • filter2.scala (created on Aug 2, 2008 5:55:43 PM UTC, 175 bytes)

@scabug
Copy link
Author

scabug commented Aug 2, 2008

@DRMacIver said:
Hm. So with Aaron Harnly's help I've narrowed it down to something which makes me fear this might be a feature rather than a bug. I'm attaching a more minimal example. Specifically the problem seems to be that Scala doesn't allow overriding a method with an implementation with an abstract method.

I feel quite strongly that this should work, but if it's by design I suppose this will require a SIP to fix.

@scabug
Copy link
Author

scabug commented Aug 2, 2008

Aaron Harnly (aaronharnly) said:
This distills to:

trait Super[A] { def foo: Super[A] = new Super[A] {} }
trait Sub[A] extends Super[A] { override def foo: Sub[A] }

@scabug
Copy link
Author

scabug commented Aug 2, 2008

Aaron Harnly (aaronharnly) said:
Or actually, I'm just too used to having type parameters. It just distills to:

trait Super { def foo: Super = new Super {} }
trait Sub extends Super { override def foo: Sub }

@scabug
Copy link
Author

scabug commented Aug 2, 2008

@DRMacIver said:
Martin says this is by design. Fair enough. Would it be possible to get a less confusing error message? The current one gives no indication of what's actually the problem (that an abstract member is overriding a concrete one)

@scabug
Copy link
Author

scabug commented Aug 5, 2008

@odersky said:
fixed in r15705

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants