New Issue: [Bug]: having a ref hash function causes an extra, unsilenceable warning

24881, "lydia-duncan", "[Bug]: having a ref hash function causes an extra, unsilenceable warning", "2024-04-17T21:55:09Z"

Summary of Problem

Description:
We've deprecated inferring a method to be ref if it modifies its this argument. If a hash function happens to be ref, though, you will still get a warning even if the hash function itself is declared to be ref, because we generate a wrapper to call that hash function and that wrapper is inferring that it must be ref. This is something the compiler is creating, so the user basically has no ability to silence the warning

Is this a blocking issue with no known work-arounds?
no, the code still compiles just fine. It's just annoying and trains users to ignore that warning instead of resolving it. It will become a problem if the deprecation warning is turned into an error, since the user still has no control over the generated function.

Steps to Reproduce

Source Code:

record myRec: hashable {
  var x: int;

  proc ref getAndSetX() ref {
    return x;
  }

  proc ref hash(salt = 0): uint throws {
    // This is not meant to be a good hash function, just to test throwing and
    // ref
    if (salt == 0) then throw new IllegalArgumentError("salt too obvious!");
    else return getAndSetX()*salt;
  }
}

proc main() {
  var myR = new myRec(15);
  try {
    var hash1 = myR.hash();
  } catch e: IllegalArgumentError {
    writeln(e.message());
    var hash2 = myR.hash(3);
    writeln(hash2);
  } catch e {
    halt(e.message());
  }
}

Compile command:
chpl foo.chpl

Execution command:
N/A

Associated Future Test(s):
test/path/to/foo.chpl #TBD

Configuration Information

  • Output of chpl --version: chpl version 2.1.0 pre-release
  • Output of $CHPL_HOME/util/printchplenv --anonymize: Should be any
  • Back-end compiler and version, e.g. gcc --version or clang --version: N/A
  • (For Cray systems only) Output of module list: N/A