changeset 3753:47871e348144 jdk-9+144

8169093: Generics, javac not matching actual and formal arguments. Summary: Make diagnostic for type-args arity mismatch consistent with the class case Reviewed-by: vromero
author mcimadamore
date Mon, 07 Nov 2016 16:08:18 +0000
parents 82a50c8d9a43
children 2ce7c1083dcb ed2e9ef4ce42
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties test/tools/javac/diags/examples/WrongNumberTypeArgsFragment.java
diffstat 3 files changed, 41 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Nov 07 11:16:23 2016 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Nov 07 16:08:18 2016 +0000
@@ -554,7 +554,8 @@
         } else if (mt.hasTag(FORALL) && typeargtypes.nonEmpty()) {
             ForAll pmt = (ForAll) mt;
             if (typeargtypes.length() != pmt.tvars.length())
-                throw inapplicableMethodException.setMessage("arg.length.mismatch"); // not enough args
+                 // not enough args
+                throw inapplicableMethodException.setMessage("wrong.number.type.args", Integer.toString(pmt.tvars.length()));
             // Check type arguments are within bounds
             List<Type> formals = pmt.tvars;
             List<Type> actuals = typeargtypes;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon Nov 07 11:16:23 2016 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon Nov 07 16:08:18 2016 +0000
@@ -2124,6 +2124,10 @@
 compiler.misc.arg.length.mismatch=\
     actual and formal argument lists differ in length
 
+# 0: string
+compiler.misc.wrong.number.type.args=\
+    wrong number of type arguments; required {0}
+
 # 0: message segment
 compiler.misc.no.conforming.assignment.exists=\
     argument mismatch; {0}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/diags/examples/WrongNumberTypeArgsFragment.java	Mon Nov 07 16:08:18 2016 +0000
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.cant.apply.symbol
+// key: compiler.misc.wrong.number.type.args
+
+import java.util.*;
+
+class WrongNumberTypeArgsFragment {
+    void test() {
+        Arrays.<String, Integer>asList("");
+    }
+}