Unimplemented: type query for out intent formals

Any idea what the workaround is please? I hit that error in the following.

proc set(out x : [?D] ?R, y : [D] R)
{
        param two = 2:R;
        const (_nx, _ny) = D.dims();
        const (nx, ny) = (_nx.high, _ny.high);

        forall i in 1 .. nx do
        {
                for j in 1 .. ny do
                {
                        x[i, j] = (i + j * two):R;
                        y[i, j] = (i * two + j):R;
                }
        }
}

proc main
{
        param useSet = false;
        type R = real(32);
        var x, y : [1..10, 1..10] R;
        param two = 2:R;

        set(x, y);
        /* this works by the way
        {
                const (_nx, _ny) = x.domain.dims();
                const (nx, ny) = (_nx.high, _ny.high);

                forall i in 1 .. nx do
                {
                        for j in 1 .. ny do
                        {
                                x[i, j] = (i + j * two):R;
                                y[i, j] = (i * two + j):R;
                        }
                }
        }
        */
        // sum
        {
                var s = 0.0;

                for tx in x do s += tx;
                for ty in y do s += ty;

                writeln(s);
        }

        {
                const x : [1..3] R = [ 1:R, 2:R, 3:R ];
                const y : [6..8] R = [ 100:R, 200:R, 300:R ];

                writeln(x + y);
        }
}

Hi Damian -

We have implementing this in mind in adjusting out formals with type query to infer type from call site · Issue #17198 · chapel-lang/chapel · GitHub .

But anyway for now I know of two workarounds:

  1. Pass additional type arguments to set (e.g. it could be proc set(D: domain, eltType: type, out x: [D] eltType, y: [D] eltType)
  2. Use ref intent rather than out intent for x (i.e. proc set(ref x : [?D] ?R, y : [D] R))

Thanks Michael. The second options looks like the way to go.

Your notes above probably need to be in the current documentation. As far as I can tell, the current behaviour of out does not comply with how I read that documentation.

I've created a PR Update the spec to clarify out type inference by mppf · Pull Request #19744 · chapel-lang/chapel · GitHub with draft updates to the spec.