Meaning of in and in out modes in Spark, and regards to non-mutable parameterized types

No.
You’re running into the same issue with unconstrained vs constrained types that trips newcomers up. (Particularly strings, which I explain here & here.)

For a quick illustration, consider:

Type Message(Length : Natural) is record
  Text : String(1..Length):= (Others => ' ');
End record;

Invalid : Message;
Valid_1 : Message(5);
Valid_2 : Message:= (Length => 5, Text => "Hello");

Now, as you can see, Valid_2 initializes with a valid object, and the compiler can therefore take those properties as its constraints. However, Valid_1 doesn’t have an object initializing it, but is instead supplying those constraints itself. Last, Invalid is not constrained by initialization, nor by subtype-constraint, and therefore the compiler cannot determine its size.

Now, when it comes to parameter-modes, something similar happens, in that even if the parameter is unconstrained, it cannot be called to operate on a value which is not itself constrained —just as the above shows— and therefore, the object it is called with determines those constraints. Consider:

Procedure Reset( Object : out Message ) is
Begin
   Object.Text:= (Object.Text'Range => ' ');
End Reset;

-- …
Reset( Valid_2 );

In this case, Valid_2 provides the constraint [that of Length-5], and therefore the range therein is 1..5.

1 Like