Skip to content

Commit

Permalink
compiler/checker: distinguish arrays and slices in duplicate index error
Browse files Browse the repository at this point in the history
For #385
  • Loading branch information
gazerro committed Jun 25, 2021
1 parent ee5b907 commit 7e4919e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/checker_expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,7 @@ func (tc *typechecker) checkCompositeLiteral(node *ast.CompositeLiteral, typ ref
if keyTi.IsConstant() {
index := int(keyTi.Constant.int64())
if _, ok := hasIndex[index]; ok {
panic(tc.errorf(node, "duplicate index in array literal: %s", kv.Key))
panic(tc.errorf(node, "duplicate index in %s literal: %s", ti.Type.Kind(), kv.Key))
}
hasIndex[index] = struct{}{}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ var checkerStmts = map[string]string{
`_ = [][]int{[]string{"a", "f"}, []string{"g", "h"}}`: `cannot use []string literal (type []string) as type []int in slice literal`,
`_ = []int{-3: 9}`: `index must be non-negative integer constant`,
`_ = []int{"a"}`: `cannot use "a" (type untyped string) as type int in slice literal`,
`_ = []int{1:10, 1:20}`: `duplicate index in array literal: 1`,
`_ = []int{1:10, 1:20}`: `duplicate index in slice literal: 1`,

// Arrays.
`_ = [1]int{1}`: ok,
Expand Down

0 comments on commit 7e4919e

Please sign in to comment.