From 7e4919e81b5948fc5525f3ec64f4e725ef9b9ef6 Mon Sep 17 00:00:00 2001 From: Marco Date: Fri, 25 Jun 2021 23:16:16 +0200 Subject: [PATCH] compiler/checker: distinguish arrays and slices in duplicate index error For #385 --- compiler/checker_expressions.go | 2 +- compiler/checker_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/checker_expressions.go b/compiler/checker_expressions.go index afee02e44..5c47a172d 100644 --- a/compiler/checker_expressions.go +++ b/compiler/checker_expressions.go @@ -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{}{} } diff --git a/compiler/checker_test.go b/compiler/checker_test.go index 149328314..2f8920e79 100644 --- a/compiler/checker_test.go +++ b/compiler/checker_test.go @@ -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,