[SR-13313] Redundant Int casting for Array Index #55753
Labels
casting
Feature: explicit casting (is, as, as? and as!)
compiler
The Swift compiler in itself
feature
A feature request or implementation
improvement
type checker
Area → compiler: Semantic analysis
will not do
Resolution: Will not be worked on
Additional Detail from JIRA
md5: e2a8738d44ee72e782637ef0cb70b37d
Issue Description:
Hi,
The above code snippet produces error
cannot convert value of type 'UInt' to expected argument type 'Int'
To solve the above error, I had to cast the index expression to Int
Since any UInt covers
only positive integers,
is a subset of Int (which also includes negative numbers)
In a way UInt is safe for Array as it omits negative range thereby preventing array index out of bounds crashes,
Isn't type checking UInt for Array index redundant?
I believe we can allow UInt variants for Array indices without any problems.
Thanks,
Nikhil.
The text was updated successfully, but these errors were encountered: