Class SlotAssignedOnce
It is the MAY half of the existing flow state. The MUST half - "set on every path that reaches here" - is the
E08060 path state, read through SymbolsAndScopes, and callers still ask it first (it also sees what a
this(...) delegate set). Must-set cannot see a slot set on only SOME paths, which is exactly the leak: set
in one arm of an if and set again after it, set in a try body and again in its catch, or
set in a loop body that runs twice. This answers, from the parse tree alone, with the slot's earlier assignments
recorded in source order (the listener's walk order):
- an assignment inside a loop body (
while,do,for) that lies within the slot's owner can run again, so the slot may already hold the value the previous iteration stored; - an earlier assignment to the same slot in the same owner may already have run, unless the two are in
DIFFERENT arms of one
if/else if/elseor oneswitch(its cases and default) - the only constructs where at most one of two places runs. Atrybody and itscatchare not exclusive: the body may have stored the value before something after it threw.
The OWNER is the nearest enclosing body (function, method, operator, service operation, dynamic function) or the
switch/try/while/for whose own returning variable or try resource the slot is - so
a loop AROUND a switch expression does not count against the switch's returning variable, which is a new variable
each time the switch runs, while a while expression's own body does count against its returning variable.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) booleanmayAlreadyHold(ISymbol slot, org.antlr.v4.runtime.tree.ParseTree assignment) True when the slot may already hold a value at this assignment, judged from the assignments recorded so far; the assignment is then recorded, so call this once for every assignment to the slot, in source order.
-
Constructor Details
-
SlotAssignedOnce
SlotAssignedOnce(SymbolsAndScopes symbolsAndScopes)
-
-
Method Details
-
mayAlreadyHold
True when the slot may already hold a value at this assignment, judged from the assignments recorded so far; the assignment is then recorded, so call this once for every assignment to the slot, in source order.
-