New Issue: instantiation+implicit conversion for numeric types

20011, "mppf", "instantiation+implicit conversion for numeric types", "2022-06-15T18:13:34Z"

Today, the compiler supports certain patterns of instantiation + implicit conversion for class types. However it does not support it for numeric types.

Here is an example that would need implicit conversions + instantiation with numeric types in order to compile:

proc f(x: chpl_anyreal, y: chpl_anyreal) {
  writeln("  f(", x.type:string, ",", y.type:string, ")");
}

var myInt: int = 1;
var myUint: uint = 2;
f(myInt, myInt);
f(myUint, myUint);
f(myInt, myUint);

This does not compile since the first f call fails to resolve. However, the compiler could know that, since int can implicitly convert to real, it can instantiate f with real and pass to that instantiation.

We have wanted to replace the stamping-out for each integer width currently done with e.g. proc g(arg: int(?w)) with some sort of generic argument processing. Doing so would run into this issue.

See also User-defined Coercion and Cast Syntax · Issue #5054 · chapel-lang/chapel · GitHub which discusses an example where this kind of functionality would be relevant if/when we add user-defined implicit conversions.