Mon, 17 Dec 2012 16:13:01 +0000
8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
Summary: Some code paths in resolve do not use methodArguments to correctly format actuals
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Dec 17 07:47:05 2012 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Dec 17 16:13:01 2012 +0000 1.3 @@ -1405,7 +1405,8 @@ 1.4 Type owntype = standaloneConditional ? condType(tree, truetype, falsetype) : pt(); 1.5 if (condtype.constValue() != null && 1.6 truetype.constValue() != null && 1.7 - falsetype.constValue() != null) { 1.8 + falsetype.constValue() != null && 1.9 + !owntype.hasTag(NONE)) { 1.10 //constant folding 1.11 owntype = cfolder.coerce(condtype.isTrue() ? truetype : falsetype, owntype); 1.12 }
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Mon Dec 17 07:47:05 2012 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Mon Dec 17 16:13:01 2012 +0000 2.3 @@ -3064,16 +3064,20 @@ 2.4 if (hasLocation) { 2.5 return diags.create(dkind, log.currentSource(), pos, 2.6 errKey, kindname, idname, //symbol kindname, name 2.7 - typeargtypes, argtypes, //type parameters and arguments (if any) 2.8 + typeargtypes, args(argtypes), //type parameters and arguments (if any) 2.9 getLocationDiag(location, site)); //location kindname, type 2.10 } 2.11 else { 2.12 return diags.create(dkind, log.currentSource(), pos, 2.13 errKey, kindname, idname, //symbol kindname, name 2.14 - typeargtypes, argtypes); //type parameters and arguments (if any) 2.15 + typeargtypes, args(argtypes)); //type parameters and arguments (if any) 2.16 } 2.17 } 2.18 //where 2.19 + private Object args(List<Type> args) { 2.20 + return args.isEmpty() ? args : methodArguments(args); 2.21 + } 2.22 + 2.23 private String getErrorKey(KindName kindname, boolean hasTypeArgs, boolean hasLocation) { 2.24 String key = "cant.resolve"; 2.25 String suffix = hasLocation ? ".location" : "";
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/lambda/BadMethodCall2.java Mon Dec 17 16:13:01 2012 +0000 3.3 @@ -0,0 +1,13 @@ 3.4 +/** 3.5 + * @test /nodynamiccopyright/ 3.6 + * @bug 8004099 3.7 + * @summary Bad compiler diagnostic generated when poly expression is passed to non-existent method 3.8 + * @compile/fail/ref=BadMethodCall2.out -XDrawDiagnostics BadMethodCall2.java 3.9 + */ 3.10 +class BadMethodCall2 { 3.11 + void test(Object rec) { 3.12 + rec.nonExistent(System.out::println); 3.13 + rec.nonExistent(()->{}); 3.14 + rec.nonExistent(true ? "1" : "2"); 3.15 + } 3.16 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/lambda/BadMethodCall2.out Mon Dec 17 16:13:01 2012 +0000 4.3 @@ -0,0 +1,4 @@ 4.4 +BadMethodCall2.java:9:13: compiler.err.cant.resolve.location.args: kindname.method, nonExistent, , @310, (compiler.misc.location.1: kindname.variable, rec, java.lang.Object) 4.5 +BadMethodCall2.java:10:13: compiler.err.cant.resolve.location.args: kindname.method, nonExistent, , @357, (compiler.misc.location.1: kindname.variable, rec, java.lang.Object) 4.6 +BadMethodCall2.java:11:13: compiler.err.cant.resolve.location.args: kindname.method, nonExistent, , @391, (compiler.misc.location.1: kindname.variable, rec, java.lang.Object) 4.7 +3 errors