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

Archie L. Cobbs duke at openjdk.org
Thu Nov 17 19:10:59 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 two additional commits since the last revision:

 - 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/d497ed13..2615d24b

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

  Stats: 232655 lines in 2313 files changed: 113387 ins; 82545 del; 36723 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