8029301: Confusing error message for array creation method reference

Reviewed-by: vromero
This commit is contained in:
Archie L. Cobbs 2023-03-22 21:00:27 +00:00 committed by Vicente Romero
parent e73411a235
commit 91f407d6fe
4 changed files with 29 additions and 7 deletions

View File

@ -4174,6 +4174,8 @@ public class Resolve {
Pair<Symbol, JCDiagnostic> c = errCandidate();
Symbol ws = c.fst.asMemberOf(site, types);
UnaryOperator<JCDiagnostic> rewriter = compactMethodDiags ?
d -> MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, c.snd) : null;
// 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.
@ -4182,18 +4184,25 @@ public class Resolve {
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,
rewriter,
kindName(ws),
ws.name == names.init ? ws.owner.name : ws.name,
kindName(ws.owner),
ws.owner.type,
c.snd);
default:
// Avoid saying "constructor Array in class Array"
if (ws.owner == syms.arrayClass && ws.name == names.init) {
return diags.create(dkind, log.currentSource(), pos,
"cant.apply.array.ctor",
rewriter,
methodArguments(ws.type.getParameterTypes()),
methodArguments(argtypes),
c.snd);
}
return diags.create(dkind, log.currentSource(), pos,
"cant.apply.symbol",
compactMethodDiags ?
d -> MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, c.snd) : null,
rewriter,
kindName(ws),
ws.name == names.init ? ws.owner.name : ws.name,
methodArguments(ws.type.getParameterTypes()),

View File

@ -260,6 +260,13 @@ compiler.misc.cant.apply.symbol=\
found: {3}\n\
reason: {6}
# 0: list of type or message segment, 1: list of type or message segment, 2: message segment
compiler.misc.cant.apply.array.ctor=\
cannot create array from given types\n\
required: {0}\n\
found: {1}\n\
reason: {2}
# 0: symbol kind, 1: name, 2: list of type
compiler.misc.cant.apply.symbols=\
no suitable {0} found for {1}({2})

View File

@ -26,6 +26,8 @@
// key: compiler.misc.no.conforming.assignment.exists
// key: compiler.misc.cant.apply.symbol
// key: compiler.misc.invalid.mref
// key: compiler.misc.cant.apply.array.ctor
// key: compiler.misc.arg.length.mismatch
class CantApplySymbolFragment {
@ -38,4 +40,8 @@ class CantApplySymbolFragment {
void test() {
SAM s = CantApplySymbolFragment::f;
}
void test2() {
Runnable x = String[]::new;
}
}

View File

@ -1,6 +1,6 @@
MethodReference60.java:26:44: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Array, int, compiler.misc.no.args, kindname.class, Array, (compiler.misc.arg.length.mismatch)))
MethodReference60.java:27:44: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Array, int, int,int, kindname.class, Array, (compiler.misc.arg.length.mismatch)))
MethodReference60.java:28:44: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Array, int, java.lang.String, kindname.class, Array, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, int))))
MethodReference60.java:26:44: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.array.ctor: int, compiler.misc.no.args, (compiler.misc.arg.length.mismatch)))
MethodReference60.java:27:44: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.array.ctor: int, int,int, (compiler.misc.arg.length.mismatch)))
MethodReference60.java:28:44: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.array.ctor: int, java.lang.String, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, int))))
MethodReference60.java:29:42: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.mref: (compiler.misc.inconvertible.types: int[], java.lang.Integer))
MethodReference60.java:30:44: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.mref: (compiler.misc.inconvertible.types: int[], java.lang.Integer[]))
5 errors