5017953: spurious cascaded diagnostics when name not found
When an operator is applied to one or more erroneous operands, spurious diagnostics are generated Reviewed-by: jjg
This commit is contained in:
parent
79d1b7b1e1
commit
6ded62c828
langtools
src/share/classes/com/sun/tools/javac/comp
test/tools/javac
@ -1991,7 +1991,9 @@ public class Attr extends JCTree.Visitor {
|
||||
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 @@ public class Attr extends JCTree.Visitor {
|
||||
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 @@ public class Attr extends JCTree.Visitor {
|
||||
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,
|
||||
|
@ -2566,9 +2566,9 @@ public class Check {
|
||||
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;
|
||||
}
|
||||
|
@ -2049,8 +2049,14 @@ public class Resolve {
|
||||
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);
|
||||
|
20
langtools/test/tools/javac/5017953/T5017953.java
Normal file
20
langtools/test/tools/javac/5017953/T5017953.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
8
langtools/test/tools/javac/5017953/T5017953.out
Normal file
8
langtools/test/tools/javac/5017953/T5017953.out
Normal file
@ -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
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user