Skip to content

Commit

Permalink
Fix a crash when encountering composite literals without a type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Thomson committed Oct 12, 2017
1 parent 2943542 commit 4881570
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion goblin.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,21 @@ func DumpExpr(e ast.Expr, fset *token.FileSet) map[string]interface{} {
}

if n, ok := e.(*ast.CompositeLit); ok {
// unlike most 'type' nodes, types in CompositeLits can be omitted,
// e.g. when you have a composite inside another one, which gives the
// inner composites an implicit type:
// bool[][] { { false, true }, { true, false }}

var declared map[string]interface{} = nil

if n.Type != nil {
declared = DumpExprAsType(n.Type, fset)
}

return map[string]interface{}{
"kind": "literal",
"type": "composite",
"declared": DumpExprAsType(n.Type, fset),
"declared": declared,
"values": DumpExprs(n.Elts, fset),
"position": DumpPosition(fset.Position(e.Pos())),
}
Expand Down

0 comments on commit 4881570

Please sign in to comment.