On this page
B3002: out parameter might not be assigned
Catalog status: active. Default severity: error. Stable name: out-parameter-unset. Family: Flow and effects.
An out parameter carries a result back to the caller, so it must be assigned on every path that returns. On the path shown, the subprogram returns without assigning it, and the caller would read an unassigned value.
Example (Vada)
procedure Find (Key : Integer; Found : out Boolean; Where : out Integer) is
begin
Found := Key > 0;
if Found then
Where := Key; -- Where is unassigned when Found is False
end if;
end Find;Example (Varc)
pub fn find(key: Integer, found: out Boolean, where: out Integer) {
found = key > 0;
if found {
where = key; // where is unassigned when found is False
}
}
What to do (Vada)
Assign the parameter on every path (a default at the start is often clearest), or make it in out if the caller's value should pass through unchanged.
What to do (Varc)
Assign the parameter on every path (a default at the start is often clearest), or make it inout if the caller's value should pass through unchanged.
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.