Currently, int is allowed as index for indexed types (arrays and strings). The reason we can't restrict this to uint is that we want to be able to use expressions like - n 1 as indices. The current implementation of the - operator types to int even if both operands are uint because the result of a subtraction may be negative.
A possible solution is to implement proper 32- or 64-bit unsigned integers and wrap around when a negative value is produced, but this would raise the problem of deciding the width. A possible solution to this would in turn be to provide both 32-bit and 64-bit integer types.
Currently,
intis allowed as index for indexed types (arrays and strings). The reason we can't restrict this touintis that we want to be able to use expressions like- n 1as indices. The current implementation of the-operator types tointeven if both operands areuintbecause the result of a subtraction may be negative.A possible solution is to implement proper 32- or 64-bit unsigned integers and wrap around when a negative value is produced, but this would raise the problem of deciding the width. A possible solution to this would in turn be to provide both 32-bit and 64-bit integer types.