Skip to content

Commit 4881570

Browse files
author
Patrick Thomson
committed
Fix a crash when encountering composite literals without a type.
1 parent 2943542 commit 4881570

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

goblin.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,21 @@ func DumpExpr(e ast.Expr, fset *token.FileSet) map[string]interface{} {
289289
}
290290

291291
if n, ok := e.(*ast.CompositeLit); ok {
292+
// unlike most 'type' nodes, types in CompositeLits can be omitted,
293+
// e.g. when you have a composite inside another one, which gives the
294+
// inner composites an implicit type:
295+
// bool[][] { { false, true }, { true, false }}
296+
297+
var declared map[string]interface{} = nil
298+
299+
if n.Type != nil {
300+
declared = DumpExprAsType(n.Type, fset)
301+
}
302+
292303
return map[string]interface{}{
293304
"kind": "literal",
294305
"type": "composite",
295-
"declared": DumpExprAsType(n.Type, fset),
306+
"declared": declared,
296307
"values": DumpExprs(n.Elts, fset),
297308
"position": DumpPosition(fset.Position(e.Pos())),
298309
}

0 commit comments

Comments
 (0)