literal array indices (#11424)

This commit is contained in:
Jasper Jenkins
2019-06-18 05:16:33 -07:00
committed by Andreas Rumpf
parent c99ce5051e
commit 8ee0f14ab6
5 changed files with 44 additions and 4 deletions

View File

@@ -548,3 +548,12 @@ block t3899:
x.a[i]
const c = O(a: [1.0,2.0])
echo c[2]
block arrayLiterals:
type ABC = enum A, B, C
template Idx[IdxT, ElemT](arr: array[IdxT, ElemT]): untyped = IdxT
doAssert [A: 0, B: 1].Idx is range[A..B]
doAssert [A: 0, 1, 3].Idx is ABC
doAssert [1: 2][1] == 2
doAssert [-1'i8: 2][-1] == 2
doAssert [-1'i8: 2, 3, 4, 5].Idx is range[-1'i8..2'i8]

View File

@@ -0,0 +1,6 @@
discard """
errormsg: "size of array exceeds range of index type 'range 1..2(Color)' by 3 elements"
line: 6
"""
type Color = enum Red, Green, Blue
let y = [Green: 0, 1, 2, 3, 4]

View File

@@ -0,0 +1,5 @@
discard """
errormsg: "expected ordinal value for array index, got '\"string\"'"
line: 5
"""
let x = ["string": 0, "index": 1]

View File

@@ -0,0 +1,5 @@
discard """
errormsg: "size of array exceeds range of index type 'range 2147483646..2147483647(int32)' by 1 elements"
line: 5
"""
echo [high(int32)-1: 1, 2, 3]