Skip to content

Commit 59d460b

Browse files
committed
fix: identify method with TypeName.FunctionName
1 parent 8c45010 commit 59d460b

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/compress/golang/plugin/go_ast.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ func (p *goParser) parseFile(filePath string) (map[string]*Function, error) {
211211
})
212212

213213
// update detailed function call info
214-
f := p.getOrSetFunc(pkgPath, funcDecl.Name.Name)
214+
name := funcDecl.Name.Name
215+
if isMethod {
216+
name = associatedStruct.Name + "." + name
217+
}
218+
f := p.getOrSetFunc(pkgPath, name)
215219
*f = Function{
216220
Name: funcDecl.Name.Name,
217221
PkgPath: pkgPath,
@@ -224,7 +228,7 @@ func (p *goParser) parseFile(filePath string) (map[string]*Function, error) {
224228
InternalMethodCalls: methodCalls,
225229
ThirdPartyMethodCalls: thirdPartyMethodCalls,
226230
}
227-
fileFuncs[funcDecl.Name.Name] = f
231+
fileFuncs[name] = f
228232
}
229233
return true
230234
})

testdata/golang/cmd/serdes.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ func InternalFunc(in []byte) {
3131
}
3232
}
3333

34+
func DuplicateName() {
35+
}
36+
3437
type Struct struct {
3538
Field1 string
3639
Field2 pkg.StructA
@@ -45,3 +48,6 @@ func (s *Struct) InternalMethod(in []byte) {
4548
println(err.Error())
4649
}
4750
}
51+
52+
func (s *Struct) DuplicateName(in []byte) {
53+
}

0 commit comments

Comments
 (0)