changeset 915:875262e89b52

5017953: spurious cascaded diagnostics when name not found Summary: when an operator is applied to one or more erroneous operands, spurious diagnostics are generated Reviewed-by: jjg
author mcimadamore
date Thu, 03 Feb 2011 09:36:28 +0000
parents 899f7c3d9426
children 03cf47d4de15
files src/share/classes/com/sun/tools/javac/comp/Attr.java src/share/classes/com/sun/tools/javac/comp/Check.java src/share/classes/com/sun/tools/javac/comp/Resolve.java test/tools/javac/5017953/T5017953.java test/tools/javac/5017953/T5017953.out test/tools/javac/6491592/T6491592.out
diffstat 6 files changed, 47 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Feb 03 09:35:21 2011 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Feb 03 09:36:28 2011 +0000
@@ -1991,7 +1991,9 @@
             tree.pos(), tree.getTag() - JCTree.ASGOffset, env,
             owntype, operand);
 
-        if (operator.kind == MTH) {
+        if (operator.kind == MTH &&
+                !owntype.isErroneous() &&
+                !operand.isErroneous()) {
             chk.checkOperator(tree.pos(),
                               (OperatorSymbol)operator,
                               tree.getTag() - JCTree.ASGOffset,
@@ -2016,7 +2018,8 @@
             rs.resolveUnaryOperator(tree.pos(), tree.getTag(), env, argtype);
 
         Type owntype = types.createErrorType(tree.type);
-        if (operator.kind == MTH) {
+        if (operator.kind == MTH &&
+                !argtype.isErroneous()) {
             owntype = (JCTree.PREINC <= tree.getTag() && tree.getTag() <= JCTree.POSTDEC)
                 ? tree.arg.type
                 : operator.type.getReturnType();
@@ -2052,7 +2055,9 @@
             rs.resolveBinaryOperator(tree.pos(), tree.getTag(), env, left, right);
 
         Type owntype = types.createErrorType(tree.type);
-        if (operator.kind == MTH) {
+        if (operator.kind == MTH &&
+                !left.isErroneous() &&
+                !right.isErroneous()) {
             owntype = operator.type.getReturnType();
             int opc = chk.checkOperator(tree.lhs.pos(),
                                         (OperatorSymbol)operator,
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Feb 03 09:35:21 2011 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Feb 03 09:36:28 2011 +0000
@@ -2566,9 +2566,9 @@
                        Type right) {
         if (operator.opcode == ByteCodes.error) {
             log.error(pos,
-                      "operator.cant.be.applied",
+                      "operator.cant.be.applied.1",
                       treeinfo.operatorName(tag),
-                      List.of(left, right));
+                      left, right);
         }
         return operator.opcode;
     }
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Feb 03 09:35:21 2011 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Feb 03 09:36:28 2011 +0000
@@ -2049,8 +2049,14 @@
                 return null;
 
             if (isOperator(name)) {
-                return diags.create(dkind, log.currentSource(),
-                        pos, "operator.cant.be.applied", name, argtypes);
+                boolean isUnaryOp = argtypes.size() == 1;
+                String key = argtypes.size() == 1 ?
+                    "operator.cant.be.applied" :
+                    "operator.cant.be.applied.1";
+                Type first = argtypes.head;
+                Type second = !isUnaryOp ? argtypes.tail.head : null;
+                return diags.create(dkind, log.currentSource(), pos,
+                        key, name, first, second);
             }
             else {
                 Symbol ws = sym.asMemberOf(site, types);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/5017953/T5017953.java	Thu Feb 03 09:36:28 2011 +0000
@@ -0,0 +1,20 @@
+/*
+ * @test  /nodynamiccopyright/
+ * @bug 5017953
+ * @summary spurious cascaded diagnostics when name not found
+ * @compile/fail/ref=T5017953.out -XDrawDiagnostics T5017953.java
+ */
+
+class T5017953 {
+
+    int f = 0;
+    void test(int i) {}
+
+    {   test(NonExistentClass.f ++);
+        test(1 + NonExistentClass.f);
+        test(NonExistentClass.f + 1);
+        test(NonExistentClass.f + NonExistentClass.f);
+        test(NonExistentClass.f += 1);
+        test(f += NonExistentClass.f);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/5017953/T5017953.out	Thu Feb 03 09:36:28 2011 +0000
@@ -0,0 +1,8 @@
+T5017953.java:13:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
+T5017953.java:14:18: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
+T5017953.java:15:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
+T5017953.java:16:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
+T5017953.java:16:35: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
+T5017953.java:17:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
+T5017953.java:18:19: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
+7 errors
--- a/test/tools/javac/6491592/T6491592.out	Thu Feb 03 09:35:21 2011 +0000
+++ b/test/tools/javac/6491592/T6491592.out	Thu Feb 03 09:36:28 2011 +0000
@@ -1,2 +1,2 @@
-T6491592.java:12:11: compiler.err.operator.cant.be.applied: +, java.lang.Object,compiler.misc.type.null
+T6491592.java:12:11: compiler.err.operator.cant.be.applied.1: +, java.lang.Object, compiler.misc.type.null
 1 error