diff options
author | Araq <rumpf_a@web.de> | 2019-09-02 12:07:27 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2019-09-02 12:07:36 +0200 |
commit | 23c44f009a0d69f7f7f536687b5e3d18e0c370d3 (patch) | |
tree | e1895d711710bfffb2b5f6d62b836179da7db903 | |
parent | 3d4ad9739cb2055bb037e9795fae7e015dc186e4 (diff) | |
download | Nim-23c44f009a0d69f7f7f536687b5e3d18e0c370d3.tar.gz |
weaking unsigned/signed indexing requirements in order to not break too much existing code
-rw-r--r-- | compiler/sigmatch.nim | 10 | ||||
-rw-r--r-- | tests/range/trange.nim | 6 |
2 files changed, 11 insertions, 5 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index d30703943..5ddb4c30b 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -380,7 +380,7 @@ proc handleRange(f, a: PType, min, max: TTypeKind): TTypeRelation = isIntLit(ab) and getInt(ab.n) >= firstOrd(nil, f) and getInt(ab.n) <= lastOrd(nil, f): # passing 'nil' to firstOrd/lastOrd here as type checking rules should - # not depent on the target integer size configurations! + # not depend on the target integer size configurations! # integer literal in the proper range; we want ``i16 + 4`` to stay an # ``int16`` operation so we declare the ``4`` pseudo-equal to int16 result = isFromIntLit @@ -396,7 +396,7 @@ proc handleRange(f, a: PType, min, max: TTypeKind): TTypeRelation = f.kind in {tyUInt8..tyUInt32} and a[0].kind in {tyUInt8..tyInt32}) and a.n[0].intVal >= firstOrd(nil, f) and a.n[1].intVal <= lastOrd(nil, f): # passing 'nil' to firstOrd/lastOrd here as type checking rules should - # not depent on the target integer size configurations! + # not depend on the target integer size configurations! result = isConvertible else: result = isNone @@ -408,13 +408,13 @@ proc isConvertibleToRange(f, a: PType): bool = of tyInt16: result = isIntLit(a) or a.kind in {tyInt8, tyInt16} of tyInt32: result = isIntLit(a) or a.kind in {tyInt8, tyInt16, tyInt32} # This is wrong, but seems like there's a lot of code that relies on it :( - of tyInt: result = true + of tyInt, tyUInt, tyUInt64: result = true of tyInt64: result = isIntLit(a) or a.kind in {tyInt8, tyInt16, tyInt32, tyInt, tyInt64} of tyUInt8: result = isIntLit(a) or a.kind in {tyUInt8} of tyUInt16: result = isIntLit(a) or a.kind in {tyUInt8, tyUInt16} of tyUInt32: result = isIntLit(a) or a.kind in {tyUInt8, tyUInt16, tyUInt32} - of tyUInt: result = isIntLit(a) or a.kind in {tyUInt8, tyUInt16, tyUInt32, tyUInt} - of tyUInt64: result = isIntLit(a) or a.kind in {tyUInt8, tyUInt16, tyUInt32, tyUInt, tyUInt64} + #of tyUInt: result = isIntLit(a) or a.kind in {tyUInt8, tyUInt16, tyUInt32, tyUInt} + #of tyUInt64: result = isIntLit(a) or a.kind in {tyUInt8, tyUInt16, tyUInt32, tyUInt, tyUInt64} else: result = false elif f.kind in {tyFloat..tyFloat128}: # `isIntLit` is correct and should be used above as well, see PR: diff --git a/tests/range/trange.nim b/tests/range/trange.nim index aac967777..c864387f6 100644 --- a/tests/range/trange.nim +++ b/tests/range/trange.nim @@ -136,3 +136,9 @@ block: const x11: range[0'f..1'f] = 2'f reject: const x12: range[0'f..1'f] = 2 + +# ensure unsigned array indexing is remains lenient: +var a: array[4'u, string] + +for i in 0..<a.len: + a[i] = "foo" |