mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 21:40:32 +00:00
error on large integer types as array index range (#23229)
fixes #17163, refs #23204
Types that aren't `tyRange` and are bigger than 16 bits, so `int32`,
`uint64`, `int` etc, are disallowed as array index range types.
`tyRange` is excluded because the max array size is backend independent
(except for the specific size of `high(uint64)` which crashes the
compiler) and so there should still be an escape hatch for people who
want bigger arrays.
(cherry picked from commit 3ab8b6b2cf)
This commit is contained in:
18
tests/array/tlargeindex.nim
Normal file
18
tests/array/tlargeindex.nim
Normal file
@@ -0,0 +1,18 @@
|
||||
discard """
|
||||
cmd: "nim check --hints:off $file"
|
||||
"""
|
||||
|
||||
# issue #17163
|
||||
var e: array[int32, byte] #[tt.Error
|
||||
^ index type 'int32' for array is too large]#
|
||||
var f: array[uint32, byte] #[tt.Error
|
||||
^ index type 'uint32' for array is too large]#
|
||||
var g: array[int64, byte] #[tt.Error
|
||||
^ index type 'int64' for array is too large]#
|
||||
var h: array[uint64, byte] #[tt.Error
|
||||
^ index type 'uint64' for array is too large]#
|
||||
|
||||
# crash in issue #23204
|
||||
proc y[N](): array[N, int] = default(array[N, int]) #[tt.Error
|
||||
^ index type 'int' for array is too large]#
|
||||
discard y[int]()
|
||||
Reference in New Issue
Block a user