diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java index 0789e9aed65..d521951041b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -4174,6 +4174,8 @@ public class Resolve { Pair c = errCandidate(); Symbol ws = c.fst.asMemberOf(site, types); + UnaryOperator 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()), diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties index 2cb524dd181..08bde947a5c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -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}) diff --git a/test/langtools/tools/javac/diags/examples/CantApplySymbolFragment.java b/test/langtools/tools/javac/diags/examples/CantApplySymbolFragment.java index 0ed248c829f..37a699e22e0 100644 --- a/test/langtools/tools/javac/diags/examples/CantApplySymbolFragment.java +++ b/test/langtools/tools/javac/diags/examples/CantApplySymbolFragment.java @@ -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; + } } diff --git a/test/langtools/tools/javac/lambda/MethodReference60.out b/test/langtools/tools/javac/lambda/MethodReference60.out index 09f82366805..7768b175a94 100644 --- a/test/langtools/tools/javac/lambda/MethodReference60.out +++ b/test/langtools/tools/javac/lambda/MethodReference60.out @@ -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