You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following program should generate 10 errors but elicits only 8. Javac complains at all 10 locations. In all instances javac's diagnostics are more precise about pattern bindings being illegally redeclared while with ecj, sometimes we emit the more bland Duplicate local variable error (which is may be just fine)
Relevant section and text of JLS21 cited inline:
public class X<T> {
public void foo(T o) {
/*
* 6.3.1 Scope for Pattern Variables in Expressions
* 6.3.1.1 Conditional-And Operator &&
*
* It is a compile-time error if any of the following conditions hold:
• A pattern variable is both (i) introduced by a when true and (ii) introduced by
b when true.
• A pattern variable is both (i) introduced by a when false and (ii) introduced by
b when false.
*/
boolean b = o instanceof String a && o instanceof Double a; // Error: correct
b = !(o instanceof String a) && !(o instanceof Double a); // <<<----- Error NOT reported by ECJ. Javac complains
/*
* 6.3.1.2 Conditional-Or Operator ||
*
* It is a compile-time error if any of the following conditions hold:
• A pattern variable is both (i) introduced by a when true and (ii) introduced by
b when true.
• A pattern variable is both (i) introduced by a when false and (ii) introduced by
b when false.
*/
b = o instanceof String a || o instanceof Double a; // <<<----- Error NOT reported by ECJ. Javac complains
b = !(o instanceof String a) || !(o instanceof Double a); // Error: correct
/*
* 6.3.1.4 Conditional Operator a ? b : c
*
* It is a compile-time error if any of the following conditions hold:
• A pattern variable is both (i) introduced by a when true and (ii) introduced by
c when true.
• A pattern variable is both (i) introduced by a when true and (ii) introduced by
c when false.
• A pattern variable is both (i) introduced by a when false and (ii) introduced by
b when true.
• A pattern variable is both (i) introduced by a when false and (ii) introduced by
b when false.
• A pattern variable is both (i) introduced by b when true and (ii) introduced by
c when true.
• A pattern variable is both (i) introduced by b when false and (ii) introduced by
c when false.
*/
b = o instanceof String a ? true : o instanceof String a; // error correctly reported
b = o instanceof String a ? true : !(o instanceof String a); // error correctly reported
b = !(o instanceof String a) ? o instanceof String a : true; // error correctly reported
b = !(o instanceof String a) ? !(o instanceof String a) : true; // error correctly reported
b = b ? (o instanceof String a) : (o instanceof String a); // error correctly reported
b = b ? !(o instanceof String a) : !(o instanceof String a); // error correctly reported
}
}
The text was updated successfully, but these errors were encountered:
The following program should generate 10 errors but elicits only 8. Javac complains at all 10 locations. In all instances javac's diagnostics are more precise about pattern bindings being illegally redeclared while with ecj, sometimes we emit the more bland
Duplicate local variable
error (which is may be just fine)Relevant section and text of JLS21 cited inline:
The text was updated successfully, but these errors were encountered: