5017953: spurious cascaded diagnostics when name not found

Thu, 03 Feb 2011 09:36:28 +0000

author
mcimadamore
date
Thu, 03 Feb 2011 09:36:28 +0000
changeset 853
875262e89b52
parent 852
899f7c3d9426
child 854
03cf47d4de15

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

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
test/tools/javac/5017953/T5017953.java file | annotate | diff | comparison | revisions
test/tools/javac/5017953/T5017953.out file | annotate | diff | comparison | revisions
test/tools/javac/6491592/T6491592.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Feb 03 09:35:21 2011 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Feb 03 09:36:28 2011 +0000
     1.3 @@ -1991,7 +1991,9 @@
     1.4              tree.pos(), tree.getTag() - JCTree.ASGOffset, env,
     1.5              owntype, operand);
     1.6  
     1.7 -        if (operator.kind == MTH) {
     1.8 +        if (operator.kind == MTH &&
     1.9 +                !owntype.isErroneous() &&
    1.10 +                !operand.isErroneous()) {
    1.11              chk.checkOperator(tree.pos(),
    1.12                                (OperatorSymbol)operator,
    1.13                                tree.getTag() - JCTree.ASGOffset,
    1.14 @@ -2016,7 +2018,8 @@
    1.15              rs.resolveUnaryOperator(tree.pos(), tree.getTag(), env, argtype);
    1.16  
    1.17          Type owntype = types.createErrorType(tree.type);
    1.18 -        if (operator.kind == MTH) {
    1.19 +        if (operator.kind == MTH &&
    1.20 +                !argtype.isErroneous()) {
    1.21              owntype = (JCTree.PREINC <= tree.getTag() && tree.getTag() <= JCTree.POSTDEC)
    1.22                  ? tree.arg.type
    1.23                  : operator.type.getReturnType();
    1.24 @@ -2052,7 +2055,9 @@
    1.25              rs.resolveBinaryOperator(tree.pos(), tree.getTag(), env, left, right);
    1.26  
    1.27          Type owntype = types.createErrorType(tree.type);
    1.28 -        if (operator.kind == MTH) {
    1.29 +        if (operator.kind == MTH &&
    1.30 +                !left.isErroneous() &&
    1.31 +                !right.isErroneous()) {
    1.32              owntype = operator.type.getReturnType();
    1.33              int opc = chk.checkOperator(tree.lhs.pos(),
    1.34                                          (OperatorSymbol)operator,
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Feb 03 09:35:21 2011 +0000
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Feb 03 09:36:28 2011 +0000
     2.3 @@ -2566,9 +2566,9 @@
     2.4                         Type right) {
     2.5          if (operator.opcode == ByteCodes.error) {
     2.6              log.error(pos,
     2.7 -                      "operator.cant.be.applied",
     2.8 +                      "operator.cant.be.applied.1",
     2.9                        treeinfo.operatorName(tag),
    2.10 -                      List.of(left, right));
    2.11 +                      left, right);
    2.12          }
    2.13          return operator.opcode;
    2.14      }
     3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Feb 03 09:35:21 2011 +0000
     3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Feb 03 09:36:28 2011 +0000
     3.3 @@ -2049,8 +2049,14 @@
     3.4                  return null;
     3.5  
     3.6              if (isOperator(name)) {
     3.7 -                return diags.create(dkind, log.currentSource(),
     3.8 -                        pos, "operator.cant.be.applied", name, argtypes);
     3.9 +                boolean isUnaryOp = argtypes.size() == 1;
    3.10 +                String key = argtypes.size() == 1 ?
    3.11 +                    "operator.cant.be.applied" :
    3.12 +                    "operator.cant.be.applied.1";
    3.13 +                Type first = argtypes.head;
    3.14 +                Type second = !isUnaryOp ? argtypes.tail.head : null;
    3.15 +                return diags.create(dkind, log.currentSource(), pos,
    3.16 +                        key, name, first, second);
    3.17              }
    3.18              else {
    3.19                  Symbol ws = sym.asMemberOf(site, types);
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/5017953/T5017953.java	Thu Feb 03 09:36:28 2011 +0000
     4.3 @@ -0,0 +1,20 @@
     4.4 +/*
     4.5 + * @test  /nodynamiccopyright/
     4.6 + * @bug 5017953
     4.7 + * @summary spurious cascaded diagnostics when name not found
     4.8 + * @compile/fail/ref=T5017953.out -XDrawDiagnostics T5017953.java
     4.9 + */
    4.10 +
    4.11 +class T5017953 {
    4.12 +
    4.13 +    int f = 0;
    4.14 +    void test(int i) {}
    4.15 +
    4.16 +    {   test(NonExistentClass.f ++);
    4.17 +        test(1 + NonExistentClass.f);
    4.18 +        test(NonExistentClass.f + 1);
    4.19 +        test(NonExistentClass.f + NonExistentClass.f);
    4.20 +        test(NonExistentClass.f += 1);
    4.21 +        test(f += NonExistentClass.f);
    4.22 +    }
    4.23 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/5017953/T5017953.out	Thu Feb 03 09:36:28 2011 +0000
     5.3 @@ -0,0 +1,8 @@
     5.4 +T5017953.java:13:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
     5.5 +T5017953.java:14:18: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
     5.6 +T5017953.java:15:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
     5.7 +T5017953.java:16:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
     5.8 +T5017953.java:16:35: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
     5.9 +T5017953.java:17:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
    5.10 +T5017953.java:18:19: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
    5.11 +7 errors
     6.1 --- a/test/tools/javac/6491592/T6491592.out	Thu Feb 03 09:35:21 2011 +0000
     6.2 +++ b/test/tools/javac/6491592/T6491592.out	Thu Feb 03 09:36:28 2011 +0000
     6.3 @@ -1,2 +1,2 @@
     6.4 -T6491592.java:12:11: compiler.err.operator.cant.be.applied: +, java.lang.Object,compiler.misc.type.null
     6.5 +T6491592.java:12:11: compiler.err.operator.cant.be.applied.1: +, java.lang.Object, compiler.misc.type.null
     6.6  1 error

mercurial