New Issue: Compiler fails to complain about initializing a 'ref' with a function returning 'const ref'

18909, "bradcray", "Compiler fails to complain about initializing a 'ref' with a function returning 'const ref'", "2022-01-04T23:57:46Z"

Summary of Problem

The Chapel compiler correctly complains when assigning a const ref to a ref as follows:

var x: int;
const ref y = x;
ref z = y;  // illegal because it throws away the const-ness

but it does not complain when assigning a function that returns a const ref to a ref:

proc foo() const ref { ... }
ref z = foo();  // shouldn't be OK, but compiler doesn't complain

and then interestingly, it does complain if z is then assigned, saying that it can't be because it's const.

Steps to Reproduce

Associated Future Test(s):
test/functions/retIntent/retConstRefToRef.chpl #18907

Configuration Information

  • Output of chpl --version: chpl version 1.26.0 pre-release (7e45422921)