Skip to content

[java-interop] Compilation error "incompatible type in overriding" when inheriting from a Java subclass with different field type to parent class (regression in 2.13) #11575

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

Closed
hughsimpson opened this issue Jun 17, 2019 · 3 comments · Fixed by scala/scala#8158

Comments

@hughsimpson
Copy link

hughsimpson commented Jun 17, 2019

Minimal to reproduce:

public class Base {
    long[] counts;
}

public class Cover extends Base {
    int[] counts;
}

Extending in Scala:

class LocalImpl extends Cover

throws incompatible type in overriding in 2.13.0 (compiles for 2.10.7, 2.11.12, 2.12.7)

@SethTisue
Copy link
Member

SethTisue commented Jun 17, 2019

Nicely minimized.

At first I thought this might be an access thing, but it's not, it's a method-vs-field thing. Make the fields public, javac still accepts it. But make the fields into methods, and javac of course says counts() in Cover cannot override counts() in Base, regardless of whether they're public-access or default-access.

It seems sad that this is even legal Java...

@retronym @adriaanm scala/scala#7671 ? scala/scala#7929 ?

@adriaanm
Copy link
Contributor

adriaanm commented Jun 17, 2019

Yeah, looks like another victim of the stricter refchecks in scala/scala#7439.
We'll need to add a few exemptions in the logic for when we're dealing with Java pairs

@adriaanm adriaanm added this to the 2.13.1 milestone Jun 17, 2019
@hughsimpson
Copy link
Author

For posterity, the workaround in my case was to use a delegate pattern and not subclass directly. cf kamon-io/Kamon@4ca896d

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

Successfully merging a pull request may close this issue.

5 participants