RFR: 8015831: Add lint check for calling overridable methods from a constructor [v7]
Archie L. Cobbs
duke at openjdk.org
Thu Jan 12 19:04:22 UTC 2023
On Thu, 12 Jan 2023 17:29:22 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> I put it there because of switch expressions and `yeild`... ?
>
> Well, yield can... yield a value - `case` doesn't. So I'm confused. Also because the variable is called `referenceExpressionNode` and `CASE` is not an expression. Can `CASE` leave anything on the stack? YIELD does, but CASE?
It's just an artifact of the way switch expressions are handled:
@Override
public void visitSwitchExpression(JCSwitchExpression tree) {
visitScoped(tree, true, t -> {
scan(t.selector);
refs.discardExprs(depth);
RefSet<ExprRef> combinedRefs = new RefSet<>();
for (List<JCCase> cases = t.cases; cases.nonEmpty(); cases = cases.tail) {
scan(cases.head);
combinedRefs.addAll(refs.removeExprs(depth));
}
refs.addAll(combinedRefs);
});
}
@Override
public void visitCase(JCCase tree) {
scan(tree.stats); // no need to scan labels
}
After scanning a switch expression case, the `yield`'ed value will be on the top of the stack.
Then `visitCase` does NOT remove it, so that it can be picked up and removed by `visitSwitchExpression()`.
But this can be cleaned up a little bit, by having `visitSwitchExpression()` not delegate to `visitCase()` but rather iterate through the case statements itself directly. Then we can remove the `CASE` as you suggest.
Also I realized we need to handle `yield`'ed values like `return` values, i.e., collect and remember them until the entire case is complete.
I'll fix.
-------------
PR: https://git.openjdk.org/jdk/pull/11874
More information about the build-dev
mailing list