New Issue: when can a different type be passed to an inout formal?

16554, “mppf”, “when can a different type be passed to an inout formal?”, “2020-10-05T16:37:24Z”

Currently, it is allowable to pass an array slice to a generic inout argument. When that happens, the formal argument is instantiated with a copy of the slice and then this is copied back to the slice after the call.

However other parts of the compiler insist that an inout formal argument match the type of the actual exactly. As a result we have what might be viewed as inconsistent behavior in the following cases:

// this works
{
  var A:[1..10] int;
  ref slice = A[1..3];
  f(slice);
}

proc f(inout arg) { }

// this does not
{
  var A:[1..10] int;
  ref slice = A[1..3];
  g(slice); // error: value from coercion passed to ref formal 'arg'
}

proc g(inout arg: [1..3] int) { }

// this does
{
  var x: int(8);
  h(x);
}

proc h(in arg: int) { }

// this does not
{
  var x: int(8);
  i(x); //  error: unresolved call 'i(int(8))'
}

proc i(inout arg: int) { }

I would propose that the compiler resolve inout similarly to in and then if there are errors doing the write -back they will occur after the function is chosen.