# HG changeset patch # User vromero # Date 1378249265 -3600 # Node ID 3bdf0c6b869c709c2df9e473b17d814557848013 # Parent ebb957ba7b074d4d223da73479d1e1bf99b50700 8023549: Compiler emitting spurious errors when constructor reference type is inferred and explicit type arguments are supplied Reviewed-by: jjg, vromero Contributed-by: maurizio.cimadamore@oracle.com diff -r ebb957ba7b07 -r 3bdf0c6b869c langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Sep 03 23:41:37 2013 +0100 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Sep 04 00:01:05 2013 +0100 @@ -2647,6 +2647,13 @@ if (that.getMode() == JCMemberReference.ReferenceMode.NEW) { exprType = chk.checkConstructorRefType(that.expr, exprType); + if (!exprType.isErroneous() && + exprType.isRaw() && + that.typeargs != null) { + log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()), + diags.fragment("mref.infer.and.explicit.params")); + exprType = types.createErrorType(exprType); + } } if (exprType.isErroneous()) { diff -r ebb957ba7b07 -r 3bdf0c6b869c langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Sep 03 23:41:37 2013 +0100 +++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Wed Sep 04 00:01:05 2013 +0100 @@ -1927,6 +1927,10 @@ compiler.misc.diamond.and.explicit.params=\ cannot use ''<>'' with explicit type parameters for constructor +# 0: unused +compiler.misc.mref.infer.and.explicit.params=\ + cannot use raw constructor reference with explicit type parameters for constructor + # 0: type, 1: list of type compiler.misc.explicit.param.do.not.conform.to.bounds=\ explicit type argument {0} does not conform to declared bound(s) {1} diff -r ebb957ba7b07 -r 3bdf0c6b869c langtools/test/tools/javac/diags/examples/MrefInferAndExplicitParams.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/diags/examples/MrefInferAndExplicitParams.java Wed Sep 04 00:01:05 2013 +0100 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.invalid.mref +// key: compiler.misc.mref.infer.and.explicit.params + +public class MrefInferAndExplicitParams { + static class Foo {} + + interface Supplier { + X make(); + } + + Supplier> sfs = Foo::new; +} diff -r ebb957ba7b07 -r 3bdf0c6b869c langtools/test/tools/javac/lambda/8023549/T8023549.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/lambda/8023549/T8023549.java Wed Sep 04 00:01:05 2013 +0100 @@ -0,0 +1,27 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8023549 + * @summary Compiler emitting spurious errors when constructor reference type is inferred and explicit type arguments are supplied + * @compile/fail/ref=T8023549.out -XDrawDiagnostics T8023549.java + */ + +public class T8023549 { + static class Foo { } + + interface Supplier { + X make(); + } + + interface ExtSupplier extends Supplier { } + + void m1(Supplier> sfs) { } + + void m2(Supplier> sfs) { } + void m2(ExtSupplier> sfs) { } + + void test() { + Supplier> sfs = Foo::new; + m1(Foo::new); + m2(Foo::new); + } +} diff -r ebb957ba7b07 -r 3bdf0c6b869c langtools/test/tools/javac/lambda/8023549/T8023549.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/lambda/8023549/T8023549.out Wed Sep 04 00:01:05 2013 +0100 @@ -0,0 +1,5 @@ +T8023549.java:23:37: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.mref.infer.and.explicit.params) +T8023549.java:24:12: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.mref.infer.and.explicit.params) +T8023549.java:25:9: compiler.err.ref.ambiguous: m2, kindname.method, m2(T8023549.Supplier>), T8023549, kindname.method, m2(T8023549.ExtSupplier>), T8023549 +T8023549.java:25:12: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.mref.infer.and.explicit.params) +4 errors