@@ -2782,7 +2782,7 @@ func typecheckcomplit(n *Node) (res *Node) {
2782
2782
}
2783
2783
elemType := n .Right .Right .Type
2784
2784
2785
- length := typecheckarraylit (elemType , - 1 , n .List .Slice ())
2785
+ length := typecheckarraylit (elemType , - 1 , n .List .Slice (), "array literal" )
2786
2786
2787
2787
n .Op = OARRAYLIT
2788
2788
n .Type = types .NewArray (elemType , length )
@@ -2804,12 +2804,12 @@ func typecheckcomplit(n *Node) (res *Node) {
2804
2804
n .Type = nil
2805
2805
2806
2806
case TARRAY :
2807
- typecheckarraylit (t .Elem (), t .NumElem (), n .List .Slice ())
2807
+ typecheckarraylit (t .Elem (), t .NumElem (), n .List .Slice (), "array literal" )
2808
2808
n .Op = OARRAYLIT
2809
2809
n .Right = nil
2810
2810
2811
2811
case TSLICE :
2812
- length := typecheckarraylit (t .Elem (), - 1 , n .List .Slice ())
2812
+ length := typecheckarraylit (t .Elem (), - 2 , n .List .Slice (), "slice literal" )
2813
2813
n .Op = OSLICELIT
2814
2814
n .Right = nodintconst (length )
2815
2815
@@ -2960,7 +2960,8 @@ func typecheckcomplit(n *Node) (res *Node) {
2960
2960
return n
2961
2961
}
2962
2962
2963
- func typecheckarraylit (elemType * types.Type , bound int64 , elts []* Node ) int64 {
2963
+ // typecheckarraylit type-checks a sequence of slice/array literal elements.
2964
+ func typecheckarraylit (elemType * types.Type , bound int64 , elts []* Node , ctx string ) int64 {
2964
2965
// If there are key/value pairs, create a map to keep seen
2965
2966
// keys so we can check for duplicate indices.
2966
2967
var indices map [int64 ]bool
@@ -2995,12 +2996,12 @@ func typecheckarraylit(elemType *types.Type, bound int64, elts []*Node) int64 {
2995
2996
r := * vp
2996
2997
r = pushtype (r , elemType )
2997
2998
r = typecheck (r , ctxExpr )
2998
- * vp = assignconv (r , elemType , "array or slice literal" )
2999
+ * vp = assignconv (r , elemType , ctx )
2999
3000
3000
3001
if key >= 0 {
3001
3002
if indices != nil {
3002
3003
if indices [key ] {
3003
- yyerror ("duplicate index in array literal : %d" , key )
3004
+ yyerror ("duplicate index in %s : %d" , ctx , key )
3004
3005
} else {
3005
3006
indices [key ] = true
3006
3007
}
0 commit comments