From ec3dc0b27b53115696229898bb5d891eec8eb0c5 Mon Sep 17 00:00:00 2001 From: Javier Feliu Date: Tue, 22 Sep 2020 15:22:29 -0400 Subject: [PATCH] issue-103 - Parser fails when processing this library https://github.com/golang/go Return immediately after we find the list is empty. --- parser/class_parser.go | 4 ++++ parser/class_parser_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/parser/class_parser.go b/parser/class_parser.go index fd435bf..82adaac 100644 --- a/parser/class_parser.go +++ b/parser/class_parser.go @@ -263,6 +263,10 @@ func (p *ClassParser) parseFileDeclarations(node ast.Decl) { func (p *ClassParser) handleFuncDecl(decl *ast.FuncDecl) { if decl.Recv != nil { + if decl.Recv.List == nil { + return + } + // Only get in when the function is defined for a structure. Global functions are not needed for class diagram theType, _ := getFieldType(decl.Recv.List[0].Type, p.allImports) theType = replacePackageConstant(theType, "") diff --git a/parser/class_parser_test.go b/parser/class_parser_test.go index f24d5be..4be0358 100644 --- a/parser/class_parser_test.go +++ b/parser/class_parser_test.go @@ -988,3 +988,15 @@ func TestGenerateRenamedStructName(t *testing.T) { t.Errorf("TestGenerateRenamedStructName: Expected result to be abcd, got %s", generatedName) } } + +func TestClassParser_handleFuncDecl(t *testing.T) { + p := &ClassParser{} + p.handleFuncDecl(&ast.FuncDecl{ + Recv: &ast.FieldList{ + List: nil, + }, + }) + if len(p.allStructs) != 0 { + t.Error("expecting no structs to be created") + } +}