Search code examples
functionrecordada

Assignment to "in" mode parameter not allowed


It seems that I can't put a record field as a parameter?

joueurActuel.c1 := predColonne(joueurActuel.c1);

The function:

function predColonne (c : T_Colonne) return T_Colonne;

where T_Colonne is a subtype of Positive.

joueurActuel is an in parameter (joueurActuel : in T_Joueur;) of a function containing the assignment above. T_Joueur is a record.


Solution

  • This is by design. A formal parameter of mode in is a constant view; it cannot be updated within the subprogram body. A constant cannot be the target of an assignment operation. See section 3.3 od Ada Reference Manual, paragraphs 13, 15, 17 and 25 in particular.

    So, either you have to store the result of predColonne(joueurActuel.c1) in a local variable, or change joueurActuel into an in out parameter if it's correct from the business logic point of view.