E1016: argument does not satisfy the parameter's role
Every parameter has a role, and the call site must state a matching role (ADR-0020).
Every parameter has a role, and the call site must state a matching role
(ADR-0020). The argument must also be able to play that role. An ins
parameter needs an exclusive loan of an active erg or dat owner. It cannot
be given a view, or a binding that is moved, frozen or suspended. An erg
parameter needs an active owner that is not frozen, or an expression of scalar
type, which is a value (ADR-0126): a literal, an operator expression, a call
result, a field or an element, as well as the result of a written
copy(value: abs x), or an expression that produces a fresh owned value
(ADR-0129): a struct or pack literal, an enum constructor, an array
constructor such as Array[Int, 2](), a call whose declared result is owned
(not abs). An if or case of aggregate type is not accepted as an
argument; bind it first. Such
a value belongs to nobody else, so it needs no binding and the callee owns it.
A view is still rejected: ref x, an abs binding and a call whose result is
abs. An erg parameter
also takes over a buffer or an arena, so the caller cannot use it after the
call (E1005); a scalar is copied and stays usable. The receiver is an
argument too: method(self: ROLE value) follows the same rules, and the
spelling value.method() is not a call (E1152). The error points at the
argument.
An argument to an erg or dat parameter that is a binding, or a field path
of a binding, of a non-scalar type must be written with its role, because the
call hands the value over (REQ-OWN-0078, ADR-0060). A scalar and a fresh owned
value need no role. For a parameter of generic type the type of the argument
decides. The receiver follows the rule like every other argument: the call
method(self: dat value) writes the role, and method(self: value) is
rejected. The method spelling value.method() was exempt until ADR-0134; it is
no longer a call and is rejected with E1152.
A ? that cannot return early from where it stands is reported with the same
code (bug #130): a ? in an argument of a verb, a method or an intrinsic such
as print, in a case guard, in the index of an assigned element, or in a
conditional, a loop or an if statement nested in the arm of a conditional
whose value an owner receives. The message names the place, and the error
points at the ?. A ? in the value of an if or case arm, on the right of
&& or ||, in a condition, a case subject or a compound assignment is
accepted and returns early.
Example
Fix
State the role that the parameter declares. When the argument is a view, the
forwarding verb must hold the same kind of access, so declare its parameter
ins too.
actus check --format json offers this as a fix: write the role keyword the parameter declares in place of the one the call wrote, or in front of an argument that has none, only when the argument can play that role (a review fix, because the role decides who owns the value; a safe fix when the omitted role is erg or dat).
An omitted erg or dat is written as the parameter declares it. This fix is
safe, because it writes the role that the compiler already executed:
A written copy is an owned value, so it is accepted for an erg parameter:
A fresh owned value is accepted without a binding (ADR-0129), and a view is still rejected (see the last example above):
Bind a propagated value before passing it on:
Run actus explain E1016 in your terminal to read this entry offline. Browse Ownership & types or all error codes.