Skip to content

Commit

Permalink
fix: correctly handle arbitrary type of literal array index
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes committed Feb 12, 2020
1 parent 681f2f9 commit 1b971b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions _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]
2 changes: 1 addition & 1 deletion interp/run.go
Expand Up @@ -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)
Expand Down

0 comments on commit 1b971b5

Please sign in to comment.