-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Ycheck failure in covariant java varargs #5140
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
Comments
The first question here is what is the intended behaviour. Specifically, is this supposed to compile? Notice it's unsound, because we're passing an Looking at the typer, the following happens while typing
I don't yet understand why step 6 happens. This is relevant to the nullability work we're doing, because we add |Null inside Java-declared array types, so so this type of covariance + arrays + java interop comes up more often in the non-null world. |
Does There is an attempt at changing how we typecheck wildcard star args in #4787. Ideally we should not type them as |
I believe if it fails to Ycheck after refchecks it should not get the area:typer flag. |
It happens to fail Ycheck later in the pipeline but this is a problem in typer. The program should not typecheck |
@allanrenucci scala 2.12.6 accepts the program. Do we know the behaviour we want? Fix the Ycheck error or disallow in the typer? |
Allow passing `Array[Dog]` to a Java varargs that expects an `Array[Animal]`. This types because Java vargs are represented as `RepeatedParam[+T]`, which is covariant. However, after `elimRepeated`, the `RP`s go away and the true type (Array) is revealed, which was causing a Ycheck error because arrays are invariant before erasure. Fix the Ycheck error by casting `Array[Dog]` to `Array[Animal]`. This is unsound but consistent with the typer behaviour and what scalac does.
Fix #5140: Ycheck failure in covariant java varargs
This involves Scala code calling a Java varargs methods.
Java
Scala
Compiling without -Ycheck succeeds, but -Ycheck:refchecks fails:
The text was updated successfully, but these errors were encountered: