RFR: 8043251: Bogus javac error: required: no arguments, found: no arguments [v2]
Archie L. Cobbs
duke at openjdk.org
Thu Dec 15 23:48:16 UTC 2022
On Thu, 17 Nov 2022 19:10:59 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
>
> 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.
keepalive
-------------
PR: https://git.openjdk.org/jdk/pull/10799
More information about the compiler-dev
mailing list