Skip to content

Commit

Permalink
issue-103 - Parser fails when processing this library https://github.…
Browse files Browse the repository at this point in the history
…com/golang/go

Return immediately after we find the list is empty.
  • Loading branch information
jfeliu007 committed Sep 22, 2020
1 parent beb9382 commit ec3dc0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions parser/class_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down
12 changes: 12 additions & 0 deletions parser/class_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit ec3dc0b

Please sign in to comment.