Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8043251: Bogus javac error: required: no arguments, found: no arguments #10799

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4173,17 +4173,34 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,

Pair<Symbol, JCDiagnostic> c = errCandidate();
Symbol ws = c.fst.asMemberOf(site, types);
return diags.create(dkind, log.currentSource(), pos,
"cant.apply.symbol",
compactMethodDiags ?
d -> MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, c.snd) : null,
kindName(ws),
ws.name == names.init ? ws.owner.name : ws.name,
methodArguments(ws.type.getParameterTypes()),
methodArguments(argtypes),
kindName(ws.owner),
ws.owner.type,
c.snd);

// If the problem is due to type arguments, then the method parameters aren't relevant,
// so use the error message that omits them to avoid confusion.
switch (c.snd.getCode()) {
case "compiler.misc.wrong.number.type.args":
case "compiler.misc.explicit.param.do.not.conform.to.bounds":
return diags.create(dkind, log.currentSource(), pos,
"cant.apply.symbol.noargs",
compactMethodDiags ?
d -> MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, c.snd) : null,
kindName(ws),
ws.name == names.init ? ws.owner.name : ws.name,
kindName(ws.owner),
ws.owner.type,
c.snd);
default:
return diags.create(dkind, log.currentSource(), pos,
"cant.apply.symbol",
compactMethodDiags ?
d -> MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, c.snd) : null,
kindName(ws),
ws.name == names.init ? ws.owner.name : ws.name,
methodArguments(ws.type.getParameterTypes()),
methodArguments(argtypes),
kindName(ws.owner),
ws.owner.type,
c.snd);
}
}

@Override
Expand Down
Expand Up @@ -233,6 +233,11 @@ compiler.err.switch.expression.no.result.expressions=\
compiler.err.call.must.be.first.stmt.in.ctor=\
call to {0} must be first statement in constructor

# 0: symbol kind, 1: name, 2: symbol kind, 3: type, 4: message segment
compiler.err.cant.apply.symbol.noargs=\
{0} {1} in {2} {3} cannot be applied to given types;\n\
reason: {4}

# 0: symbol kind, 1: name, 2: list of type or message segment, 3: list of type or message segment, 4: symbol kind, 5: type, 6: message segment
compiler.err.cant.apply.symbol=\
{0} {1} in {4} {5} cannot be applied to given types;\n\
Expand Down
10 changes: 10 additions & 0 deletions test/langtools/tools/javac/Diagnostics/8043251/T8043251.java
@@ -0,0 +1,10 @@
/**
* @test /nodynamiccopyright/
* @bug 8043251
* @summary Confusing error message with wrong number of type parameters
* @compile/fail/ref=T8043251.out -XDrawDiagnostics T8043251.java
*/
import java.util.function.Function;
class T8043251 {
Function<String, String> f = Function.<String, String>identity();
}
2 changes: 2 additions & 0 deletions test/langtools/tools/javac/Diagnostics/8043251/T8043251.out
@@ -0,0 +1,2 @@
T8043251.java:9:42: compiler.err.cant.apply.symbol.noargs: kindname.method, identity, kindname.interface, java.util.function.Function<T,R>, (compiler.misc.wrong.number.type.args: 1)
1 error
Expand Up @@ -21,7 +21,7 @@
* questions.
*/

// key: compiler.err.cant.apply.symbol
// key: compiler.err.cant.apply.symbol.noargs
// key: compiler.misc.explicit.param.do.not.conform.to.bounds

class ExplicitParamsDoNotConformToBounds {
Expand Down
Expand Up @@ -21,7 +21,7 @@
* questions.
*/

// key: compiler.err.cant.apply.symbol
// key: compiler.err.cant.apply.symbol.noargs
// key: compiler.misc.wrong.number.type.args

import java.util.*;
Expand Down