# HG changeset patch # User mcimadamore # Date 1296725788 0 # Node ID 875262e89b5251c2eacc5fc21bbe2a66379c227a # Parent 899f7c3d94268373798cc939ee7422efdc60b890 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 diff -r 899f7c3d9426 -r 875262e89b52 src/share/classes/com/sun/tools/javac/comp/Attr.java --- 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, diff -r 899f7c3d9426 -r 875262e89b52 src/share/classes/com/sun/tools/javac/comp/Check.java --- 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; } diff -r 899f7c3d9426 -r 875262e89b52 src/share/classes/com/sun/tools/javac/comp/Resolve.java --- 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); diff -r 899f7c3d9426 -r 875262e89b52 test/tools/javac/5017953/T5017953.java --- /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); + } +} diff -r 899f7c3d9426 -r 875262e89b52 test/tools/javac/5017953/T5017953.out --- /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 diff -r 899f7c3d9426 -r 875262e89b52 test/tools/javac/6491592/T6491592.out --- 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