Java 9 ea154 javac compiler error - legit or bug?
Vitaly Davidovich
vitalyd at gmail.com
Thu Feb 9 04:09:16 UTC 2017
Hi Maurizio,
Thanks for the reply. So you're saying the example using assignment
context shouldn't compile either? Also, the call to 'foo' is unchecked in
the wildcard argument, but it has a concrete type in the first argument.
Are you saying that any unchecked param results in return type erasure?
Thanks
On Wed, Feb 8, 2017 at 8:38 PM Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:
> Hi,
> it seems like the behavior you observed started in b83 - as a result of
> this:
>
> https://bugs.openjdk.java.net/browse/JDK-8078093
>
> I believe the error is correct (although the diagnostic has always been
> broken since b83 in the 'verbose' mode - the non-verbose mode - w/o
> -Xdiags:verbose is fine). That is, the call to 'foo' is unchecked, so the
> return type should be erased. There seems to be an inconsistency in how
> javac handles this in method context compared to assignment context, and
> that needs to be looked at.
>
> Thanks
>
>
> Maurizio
>
>
>
> On 08/02/17 19:23, Vitaly Davidovich wrote:
>
> Hi all,
>
> Given the following code:
>
> import java.util.ArrayList;
> import java.util.Collection;
>
> public class Foo {
> static <T> T foo(Class<T> c, Collection<? super T> baz) {
> return null;
> }
>
> static void bar(String c) {
>
> }
>
> @SuppressWarnings("unchecked")
> public static void main(String[] args) {
> // this works
> bar(foo(String.class, new ArrayList<String>()));
>
> // this works with a warning
> String s = foo(String.class, new ArrayList());
> bar(s);
>
> // this causes an error on JDK9
> bar(foo(String.class, new ArrayList()));
> }
> }
>
> javac 9-ea (build 9-ea+154) fails with this interesting error (on the last
> line in main, as the comments there indicate):
>
> Foo.java:23: error: method bar in class Foo cannot be applied to given
> types;
> bar(foo(String.class, new ArrayList()));
> ^
> required: String
> found: String
> reason: argument mismatch; Object cannot be converted to String
> 1 error
>
> Java 8 compiles fine, and the other 2 lines compile in the same java 9
> build as well.
>
> Is this a javac bug or legit? It seems like a compiler error. At a
> minimum, the diagnostic output "required String, found String" is confusing.
>
> Thanks
>
>
>
> --
Sent from my phone
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20170209/1f298e9b/attachment.html>
More information about the compiler-dev
mailing list