New Issue: What can be passed to a 'const ref' formal argument?

17195, "vasslitvinov", "What can be passed to a 'const ref' formal argument?", "2021-02-19T02:25:10Z"

Reference: argument intents in the spec

Consider a function that has a const ref formal, ex.

proc f(const ref formal: SomeType) {.....}

What kinds of expressions of the type SomeType can we use as an actual argument to f ?

Variables, including formals, record fields, etc., whether var or const, can.

We also some time ago started allowing value expressions as actuals, ex.

proc g(): SomeType { ... return ...; }
f(g()); // legal

This issue asks:

  • Are param values legal actuals here?
    Ex. what if g() above had a param intent?

While there:

  • Are we happy with allowing value expressions as actuals?
    Sounds like “it maybe slightly odd, but definitely convenient.”
  • Should we also allow value and param expressions as actuals
    to ref formals, following the same rational as for const ref formals?