Link: Extend the count (`#`) operator on ranges to accept any integral value by bradcray · Pull Request #20098 · chapel-lang/chapel · GitHub
Merge pull request #20098 from bradcray/count-any-integral
Extend the count (
#) operator on ranges to accept any integral value
Oops, my finger slipped and I double-clicked the merge accidentally
earlier than I'd intended. The following message should've gone into the
[reviewed by @lydia-duncan]
Prior to this PR, for a range of idxType
int(8) (say), the count
#) only accepted integer values of type
uint(8). This PR extends count on ranges to accept any integral
value so long as the value of the integer doesn't surpass the range's
size, essentially changing this check from "This value's static type
can store a too-large value, so let's not support it" into "There's no
reason to believe that this integer is particularly large or small based
on its type, so let's not make assumptions about it." This is
useful when working with small-int ranges and applying an
count, which is not uncommon since that's the default int type.
While here, I did some minor refactoring to the bounds checking code
# operator on ranges to make the logic slightly clearer.
No changes were required to domains and arrays because their
count operator is implemented in terms of the range type's, so they
inherit the behavior for free.
This changed a few tests from "tests of errors" into working tests,
resolved a future, and required one other test update. I also added a
new test of mixing integer types when applying
# to domains and
arrays, as they didn't seem to have existing tests.