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

Incorrect compiler error message overriding java raw type with a recursive type bound #10260

Closed
jeantil opened this issue Apr 11, 2017 · 1 comment

Comments

@jeantil
Copy link

commented Apr 11, 2017

Given the following java code:

public class A<T extends A<T>> {}
interface IA {
    void foo(A a);
}

when trying to implement the interface from scala with

class IAImpl extends IA{
  override def foo(a: A[_]): Unit = ???
}

then the scala compiler (2.10.6, 2.11.8, 2.12.1) fails with the following message:

class IAImpl needs to be abstract, since method foo in trait IA of type (a: A)Unit is not defined
(Note that A does not match A[_]. To implement a raw type, use A[_])
class IAImpl extends IA{
      ^

Which is fairly confusing since the recommendation is the same as the actual error.

After discussing this on the scala user's board it appears the correct syntax to override such a method is

class IAImpl extends IA { 
  override def foo(a: A[X] forSome {type X <: A[X]}): Unit = ??? 
}

Maybe the compiler could detect that and print a better error message ?

Jasper-M added a commit to Jasper-M/scala that referenced this issue May 9, 2017
Display raw type as existential in error message
Before, when implementing a raw type in a method override in the wrong way, the error message always suggested a simple wildcard type.
This commit changes that error message to always suggest an existential type that the user can copy paste into his code.
To that end `typeParamsToExistentials` is changed to preserve the names of the type parameters instead of changing them to "?0".."?N".

fixes scala/bug#10260
@jeantil

This comment has been minimized.

Copy link
Author

commented Sep 18, 2017

thank you !!

@adriaanm adriaanm added this to the 2.12.4 milestone Sep 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.