New Issue: What should negating a uint(32) do?

20629, "mppf", "What should negating a uint(32) do?", "2022-09-06T16:48:27Z"

This issue asks what negating a uint or a uint(32) should do. Note that these two are currently arguably inconsistent and the uint(32) behavior might be surprising in that it brings in a larger width type that the user has not been using.

var myUint: uint;
var negMyUint = -myUint; // error: illegal use of '-' on operand of type uint(64)
writeln("negMyUint = ", negMyUint, " : ", negMyUint.type:string);
var myUint32: uint(32);
var negMyUint32 = -myUint32;
writeln("negMyUint32 = ", negMyUint32, " : ", negMyUint32.type:string);
// outputs:
//  negMyUint32 = 0 : int(64)

The above behaviors are the same in 1.27 as well as after PR #20528 was merged. However, now that int to uint implicit conversions are allowed, these behaviors seem less defensible.

The compilation error comes from an error overload in ChapelBase:

inline operator -(a: uint(64)) { compilerError("illegal use of '-' on operand of type ", a.type:string); }

It seems likely that adjusting this overload (possibly with uint(?w)) will allow whatever behavior we desire here. Perhaps such adjustments were not possible before PR #20528. In any case once we have a direction here we will need to demonstrate that it can work smoothly with the current disambiguation rules from PR #20528.