node: handle trailing commas in array literals

This commit is contained in:
mappu 2020-04-11 12:45:26 +12:00
parent 48f3014429
commit 6b8d4d879a
1 changed files with 8 additions and 0 deletions

View File

@ -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 {