[Chapel Merge] Tweak error for passing a coercion value to a ref

Branch: refs/heads/master
Revision: 3aaf725
Author: dlongnecke-cray
Log Message:

Tweak error for passing a coercion value to a ref formal, add hint for classes (#16681)

Tweak error for passing a coercion value to a ref formal, add hint for classes (#16681)

The temporary value produced by a coercion cannot be passed by
reference, and attempting to do so produces an error.

The following code illustrates a scenario where this error occurs:


class C1 { var x = 0; }
class C2 : C1 { var x = 0; }

proc foo(c1: shared C1) {
  writeln(c1);
}

proc test() {
  var c2 = new shared C2();
  // error: value from coercion passed to const ref formal 'c1'
  foo(c2);
}
test();

When coercing a shared subclass to its parent class, a temporary
value is created that cannot be passed by reference. Users can
unwittingly run into this error for shared because the default intent
is const ref.

This PR tweaks the message emitted for this error to try and emphasize
that the coercion is producing a value that cannot be passed by
reference.

It also inserts an additional note explaining the types involved in
the coercion.

Below is a before and after for the error message.

Before:

test: 11: error: value from coercion passed to const ref formal 'c1'
test: 4: note: to function 'foo' defined here

After:

test: 11: error: in call to 'foo', cannot pass result of coercion by
reference
test: 11: note: implicit coercion from 'shared C2' to 'shared C1'
test: 4: note: when passing to 'const ref' intent formal 'c1'