From 1b971b539c2b4203d936834818820507f707da49 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Wed, 12 Feb 2020 15:06:04 +0100 Subject: [PATCH] fix: correctly handle arbitrary type of literal array index --- _test/a40.go | 23 +++++++++++++++++++++++ interp/run.go | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 _test/a40.go diff --git a/_test/a40.go b/_test/a40.go new file mode 100644 index 000000000..7b5be36a9 --- /dev/null +++ b/_test/a40.go @@ -0,0 +1,23 @@ +package main + +import "fmt" + +type rule uint8 + +const ( + r0 rule = iota + r1 + r2 +) + +var a = [...]int{ + r0: 1, + r1: 12, +} + +func main() { + fmt.Println(a) +} + +// Output: +// [1 12] diff --git a/interp/run.go b/interp/run.go index 7c21285a7..6c86e55f3 100644 --- a/interp/run.go +++ b/interp/run.go @@ -1461,7 +1461,7 @@ func arrayLit(n *node) { if c.kind == keyValueExpr { convertLiteralValue(c.child[1], rtype) values[i] = genValue(c.child[1]) - index[i] = int(c.child[0].rval.Int()) + index[i] = int(vInt(c.child[0].rval)) } else { convertLiteralValue(c, rtype) values[i] = genValue(c)