New Issue: Operations on mixed-size uints don't work / generate a confusing error message

17756, "bradcray", "Operations on mixed-size uints don't work / generate a confusing error message", "2021-05-17T19:15:59Z"

Summary of Problem

When subtracting an 8-bit uint from a 64-bit uint:

var u: uint = 2;
var u8: uint(8) = 1;

writeln(u-u8);

we currently generate the error message:

illegal use of '-' on operands of type uint(64) and signed integer

which is confusing because—from the user's standpoint—they aren't using a signed integer operand. This issue proposes that we either support this behavior or improve the error message.

I believe that this is occurring because we tend to coerce small uint values to larger signed int values over larger uint values. Specifically, the --explain-call flag explains that the candidates are:

note: candidates are: -(a: uint(64), b: int(64)) [17001]
note:                 -(a: uint(64), b: uint(64)) [465095]
note:                 -(a: real(64), b: real(64)) [465139]
note:                 -(a: complex(128), b: complex(128)) [465227]
note:                 -(a: real(64), b: complex(128)) [465434]
note:                 -(a: complex(128), b: real(64)) [465519]
note: best candidate is: -(a: uint(64), b: int(64)) [17001]

and then says that the best candidate is:

$CHPL_HOME/modules/internal/ChapelBase.chpl:1982: note: best candidate is: -(a: uint(64), b: int(64)) [17001]

which is an error overload. Putting the last resort pragma on this routine causes the uint/uint version to be called, so may be the right way to fix this. But it also made me wonder whether there should be something about uints that says that they prefer to coerce to uints over ints, given the choice.

Associated Future Test(s):
test/types/integral/uintMinusSmallUint.chpl #17755

Configuration Information

  • Output of chpl --version: 1.25.0 pre-release (75306b9359)