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

problem with erased generics in Java and overriding #11469

Open
adriaanm opened this Issue Apr 3, 2019 · 8 comments

Comments

Projects
None yet
3 participants
@adriaanm
Copy link
Member

commented Apr 3, 2019

looks like matching in refchecks is broken?

@adriaanm adriaanm self-assigned this Apr 3, 2019

@adriaanm

This comment has been minimized.

Copy link
Member Author

commented Apr 3, 2019

package jkson;
abstract class Erased { public abstract Object foo(); }
public abstract class Generic<T> extends Erased { public T foo() { return null; } }
abstract class ScalaGen[T] extends jkson.Generic[T]
/*
error: incompatible type in overriding
def foo(): Object (defined in class Erased)
  with def foo(): T (defined in class Generic);
 found   : ()T
 required: ()Object
*/
@adriaanm

This comment has been minimized.

Copy link
Member Author

commented Apr 3, 2019

workaround: add T <: Object bound 😏

adriaanm referenced this issue in scalacommunitybuild/jackson-module-scala Apr 3, 2019

@adriaanm

This comment has been minimized.

Copy link
Member Author

commented Apr 3, 2019

Check out the commit in the scalacommunitybuild fork. Even Product is not considered a subtype of Object??

@adriaanm

This comment has been minimized.

Copy link
Member Author

commented Apr 3, 2019

@retronym could you take a look? I'll take over in my morning (I added a test in the commit referenced below)

@adriaanm adriaanm changed the title override checks for java methods should treat Object result like Any something broken with subtyping of Object Apr 3, 2019

@adriaanm adriaanm changed the title something broken with subtyping of Object problem with erased generics in Java and overriding Apr 3, 2019

adriaanm referenced this issue in adriaanm/scala Apr 3, 2019

@adriaanm

This comment has been minimized.

Copy link
Member Author

commented Apr 3, 2019

@adriaanm adriaanm transferred this issue from scala/scala-dev Apr 3, 2019

@SethTisue SethTisue added this to the 2.13.1 milestone Apr 3, 2019

@SethTisue

This comment has been minimized.

Copy link
Member

commented Apr 3, 2019

@adriaanm 2.13.1 milestone okay?

@retronym

This comment has been minimized.

Copy link
Member

commented Apr 3, 2019

Not sure if related, but in #10418 (comment) I noted that the way we unify Object and Any in matchesType when a Java defined method is involved is too shallow and doesn't deal with class type parameters.

retronym added a commit to retronym/scala that referenced this issue Apr 4, 2019

retronym added a commit to retronym/scala that referenced this issue Apr 4, 2019

@SethTisue

This comment has been minimized.

Copy link
Member

commented Apr 6, 2019

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