How to return a link to an array fragment in the Chapel?

I try to return a reference to a slice of an array, but I get the following compile-time error (where the violation line is in slice

test.chpl: 9: error: illegal expression to return by ref

Returning a full array works fine, as does a link to a slice in the main program.

Is there a proper way to return a ref to a slice? Thanks in advance!

record R {
  var A : [0.. #10] int;

  proc full() ref {
    return A;
  }

  proc slice() ref {
    return A[0.. #5];
  }
}

var r : R;
ref x1 = r.full();
ref x2 = r.slice();
ref x3 = x1[0.. #5];

For completeness only:

chpl Version 1.16.0 preview (2659cc6)

+6
source share
1 answer

, , GitHub # 5341, , ref , .

pragma ( , , , , , ref):

record R {
  var A : [0.. #10] int;

  proc full() ref {
    return A;
  }

  pragma "no copy return"
  proc slice() {
    return A[0.. #5];
  }
}

var r : R;
ref x1 = r.full();
ref x2 = r.slice();
ref x3 = x1[0.. #5];
x1[0] = 1;
x2[1] = 2;
x3[2] = 3;
writeln(r);
+2

All Articles