Skip to content

Commit 1007c23

Browse files
committed
fix:(uniast) dedup Type.Implements
1 parent 841d3d1 commit 1007c23

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

lang/golang/parser/pkg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ func (p *GoParser) associateImplements() {
9393
for iface, iid := range p.interfaces {
9494
if types.Implements(typ, iface) {
9595
tobj := p.getRepo().GetType(tid)
96-
tobj.Implements = append(tobj.Implements, iid)
96+
tobj.Implements = Append(tobj.Implements, iid)
9797
}
9898
// 另外检查 typ 的指针类型是否实现了 iface
9999
if types.Implements(types.NewPointer(typ), iface) {
100100
tobj := p.getRepo().GetType(tid)
101-
tobj.Implements = append(tobj.Implements, iid)
101+
tobj.Implements = Append(tobj.Implements, iid)
102102
}
103103
}
104104
}

lang/uniast/utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ import (
2121
"os"
2222
)
2323

24+
func Append[T comparable](ids []T, id T) []T {
25+
for _, i := range ids {
26+
if i == id {
27+
return ids
28+
}
29+
}
30+
return append(ids, id)
31+
}
32+
2433
func InsertDependency(ids []Dependency, id Dependency) []Dependency {
2534
for _, i := range ids {
2635
if i.Identity == id.Identity {

0 commit comments

Comments
 (0)