External Issue: Compilation error when trying to return a local 'ref' variable with ref function intent

19223, "twesterhout", "Compilation error when trying to return a local 'ref' variable with ref function intent", "2022-02-08T19:06:36Z"

Steps to Reproduce

Source Code:

class Foo {
  var A : [0 ..# 5] int;

  proc getChunk(n : int) ref {
    ref r = A[0 ..# n];
    return r;
  }
}

var foo = new Foo();
writeln(foo.getChunk(4));

Compile command:

chpl error.chpl

This fails with the following error

error: Reference to scoped variable r cannot be returned

Configuration Information

  • Output of chpl --version: 1.26.0 pre-release (9382e47)

Related to #19221