Draft PR for JDK-8043251: Bogus javac error: required: no arguments, found: no arguments

Archie Cobbs archie.cobbs at gmail.com
Sat Oct 22 02:33:44 UTC 2022


I'm looking for any thoughts or comments on a draft PR
<https://github.com/openjdk/jdk/pull/10799> for JDK-8043251
<https://bugs.openjdk.org/browse/JDK-8043251> "Bogus javac error: required:
no arguments, found: no arguments"

Here's the summary:

We have an error message compiler.err.cant.apply.symbol for cases where a
> method invocation doesn't work. It shows the "required" parameters and the
> "found" parameters, plus a further description of the problem.
>
> This message being used inappropriately when the problem is actually due
> to the method's type parameters instead of its method parameters.
>
> For example, if you do this:
>
> Function<String, String> f = Function.<String, String>identity();
>
> the error reported is this:
>
> error: method identity in interface Function<T,R> cannot be applied to given types;
>     Function<String, String> f = Function.<String, String>identity();
>                                          ^
>   required: no arguments
>   found:    no arguments
>   reason: wrong number of type arguments; required 1
>   where T,R are type-variables:
>     T extends Object declared in interface Function
>     R extends Object declared in interface Function
>
> This patch creates a alternate version of that error message (
> compiler.err.cant.apply.symbol.noargs) that omits the "required" and
> "found" lines. In the example above you instead get this:
>
> error: method identity in interface Function<T,R> cannot be applied to given types;
>     Function<String, String> f = Function.<String, String>identity();
>                                          ^
>   reason: wrong number of type arguments; required 1
>   where T,R are type-variables:
>     T extends Object declared in interface Function
>     R extends Object declared in interface Function
> 1 error
>
> However, I'm not satisfied with how this patch works and am looking for
> suggestions on how to improve it (that's why this is a draft PR).
>
> Currently it simply looks for cases where the error is due to "wrong
> number of type arguments" or "explicit type argument X does not conform to
> declared bound(s)" (by checking the error key), and if so it uses the
> alternate form.
>
> At least two aspects could be improved..
>
>    - Looking at the diagnostic key to differentiate type parameter
>    mismatches vs. regular parameter mismatches seems a little kludgey. Is
>    there a better way? Maybe a new flag added to InapplicableSymbolError?
>    - Ideally, for type parameter errors we would keep the "required" and
>    "found" lines, but display the type parameters required & found instead of
>    the normal parameters required & found. Then we wouldn't even need a new
>    error message. But I'm not sure how to retrieve those.
>
> Any ideas or improvements welcome.
>
Thanks,
-Archie

-- 
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20221021/53fb0aed/attachment-0001.htm>


More information about the compiler-dev mailing list