On this page
B2014: copy of a value of a limited type
Catalog status: active. Default severity: error. Stable name: limited-copy. Family: Types and constraints.
A limited type (RM 7.5) has no assignment: its values are never copied, so that an object can stand for something unique, such as a resource or an account. An object of a limited type is given its value where it is created, by an aggregate or a function call, and its components can be changed afterwards; the whole object cannot be assigned, and an object cannot be initialised as a copy of another.
Example (Vada)
type Account is limited record
Balance : Integer := 0;
end record;
A : Account;
B : Account := A; -- a copyExample (Varc)
type Account = limited struct {
balance: Integer = 0,
}
var a: Account;
var b: Account = a; // a copy
What to do (Vada)
Build the value in place (B : Account := (Balance => 10); or B : Account := Open;), change the components you need, or make the type non-limited if copies are meant.
What to do (Varc)
Build the value in place (var b: Account = (balance: 10); or var b: Account = open();), change the components you need, or make the type non-limited if copies are meant.
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See types and constraints, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.