node: handle trailing commas in array literals
This commit is contained in:
parent
48f3014429
commit
6b8d4d879a
8
node.go
8
node.go
@ -1648,6 +1648,8 @@ func (this *conversionState) convertArrayLiteralCommon(items []node.Node) (strin
|
||||
keyType := unknownVarType
|
||||
valType := unknownVarType
|
||||
|
||||
// TODO support unpack operator (...)
|
||||
|
||||
isMapType := false
|
||||
for idx, itm_ := range items {
|
||||
itm, ok := itm_.(*expr.ArrayItem)
|
||||
@ -1655,6 +1657,12 @@ func (this *conversionState) convertArrayLiteralCommon(items []node.Node) (strin
|
||||
return "", parseErr{itm_, fmt.Errorf("expected ArrayItem")}
|
||||
}
|
||||
|
||||
// If there is a trailing comma in the definition,
|
||||
// the parser produces an empty ArrayItem with no detail information
|
||||
if itm.Key == nil && itm.Val == nil && idx == len(items)-1 {
|
||||
break
|
||||
}
|
||||
|
||||
if idx == 0 {
|
||||
isMapType = (itm.Key != nil)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user