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 type checker fails to recognize that an early return can satisfy a refinement condition.
publicclassExample {
publicstaticintdivide(inta, @Refinement("b != 0") intb) {
returna / b;
}
publicstaticvoidexample1(intx, inty) {
if (y == 0) {
System.out.println("division by zero");
} else {
divide(x, y); // correct (no error)
}
}
publicstaticvoidexample2(intx, inty) {
if (y == 0) {
System.out.println("division by zero");
return; // early return
}
divide(x, y); // should also be correct but isnt
}
}
In this example, the refinement b != 0 should be considered satisfied in both cases, since after the if (y == 0) branch returns, the only reachable path ensures y != 0.
Possible Fix
Convert early-exit branches into ternary (explicit if-else).
Activity