Integrated: 8043251: Bogus javac error: required: no arguments, found: no arguments
Archie L. Cobbs
duke at openjdk.org
Mon Jan 9 18:42:02 UTC 2023
On Thu, 20 Oct 2022 19:20:07 GMT, Archie L. Cobbs <duke at openjdk.org> wrote:
> We have an error message `compiler.err.cant.apply.symbol` for cases where a method invocation doesn't resolve. 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 explicitly passed method type parameters instead of regular 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
>
> The real error here is `wrong number of type arguments; required 1`, but the `compiler.err.cant.apply.symbol` error message that assumes the problem is with the regular parameters, which it displays. The result is the appearance of the useless and confusing `required` and `found` lines.
>
> This patch creates an alternate version of that error message (`compiler.err.cant.apply.symbol.noargs`) that omits the `required` and `found` lines, and makes the compiler use this alternate message when the error is due to type parameters (specifically, when the underlying error is "wrong number of type arguments" or "explicit type argument X does not conform to declared bound(s)").
>
> This improves the error for example above to 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
This pull request has now been integrated.
Changeset: 679e4858
Author: Archie L. Cobbs <archie.cobbs at gmail.com>
Committer: Vicente Romero <vromero at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/679e485838881c1364845072af305fb60d95e60a
Stats: 47 lines in 6 files changed: 34 ins; 0 del; 13 mod
8043251: Bogus javac error: required: no arguments, found: no arguments
Reviewed-by: vromero
-------------
PR: https://git.openjdk.org/jdk/pull/10799
More information about the compiler-dev
mailing list