On this page
B3017: hidden variable outside the package's state abstractions
Catalog status: active. Default severity: error. Stable name: hidden-state. Family: Flow and effects.
A package names its hidden state (variables in its private part, its body, or a private child package) with Abstract_State, so that clients' Global and Depends contracts can mention it without seeing the variables. Every such variable must then be a constituent of one of those states: by Part_Of => State on its declaration (private part, private child) or by naming it in the body's Refined_State. A private child can hold state only for a parent that declares a state abstraction.
Example (Vada)
package Ledger is
procedure Add (Amount : Integer);
end Ledger;
private package Ledger.Store is
Total : Integer := 0; -- whose state is this?
end Ledger.Store;Example (Varc)
// ledger.va
package Ledger {
pub fn add(amount: Integer) { ... }
}
// ledger-store.va
private package Ledger.Store {
pub var total: Integer = 0; // whose state is this?
}
What to do (Vada)
Declare the state on the parent and make the variable a constituent of it:
package Ledger
with Abstract_State => State, Initializes => State
is
procedure Add (Amount : Integer)
with Global => (In_Out => State);
end Ledger;
private package Ledger.Store is
Total : Integer := 0 with Part_Of => Ledger.State;
end Ledger.Store;
package body Ledger
with Refined_State => (State => Ledger.Store.Total)
is
...What to do (Varc)
Declare the state on the parent, refine it to the variable, and make the variable a constituent of it:
// ledger.va
package Ledger
@Abstract_State(State) @Initializes(State)
@Refined_State(State => Ledger.Store.total)
{
import Ledger.Store;
pub fn add(amount: Integer)
@Global(In_Out => State)
{
...
}
}
// ledger-store.va
private package Ledger.Store {
pub var total: Integer = 0 @Part_Of(Ledger.State);
}
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See flow and effects, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.