RFR: 8043251: Bogus javac error: required: no arguments, found: no arguments [v3]

Archie L. Cobbs duke at openjdk.org
Mon Dec 19 15:44:21 UTC 2022


> 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

Archie L. Cobbs has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:

 - Merge branch 'master' into JDK-8043251
 - Merge branch 'master' into JDK-8043251
 - Fix confusing error message regarding wrong number of type parameters.

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/10799/files
  - new: https://git.openjdk.org/jdk/pull/10799/files/2615d24b..92338830

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=10799&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=10799&range=01-02

  Stats: 136482 lines in 2312 files changed: 69468 ins; 45399 del; 21615 mod
  Patch: https://git.openjdk.org/jdk/pull/10799.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/10799/head:pull/10799

PR: https://git.openjdk.org/jdk/pull/10799


More information about the compiler-dev mailing list