Skip to content

Commit 16871ed

Browse files
authored
fix #864: confusing-naming FP on methods of generic types (#869)
1 parent 7cb4540 commit 16871ed

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

rule/confusing-naming.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@ type packages struct {
2727

2828
func (ps *packages) methodNames(lp *lint.Package) pkgMethods {
2929
ps.mu.Lock()
30+
defer ps.mu.Unlock()
3031

3132
for _, pkg := range ps.pkgs {
3233
if pkg.pkg == lp {
33-
ps.mu.Unlock()
3434
return pkg
3535
}
3636
}
3737

3838
pkgm := pkgMethods{pkg: lp, methods: make(map[string]map[string]*referenceMethod), mu: &sync.Mutex{}}
3939
ps.pkgs = append(ps.pkgs, pkgm)
4040

41-
ps.mu.Unlock()
4241
return pkgm
4342
}
4443

@@ -72,6 +71,7 @@ func (*ConfusingNamingRule) Name() string {
7271

7372
// checkMethodName checks if a given method/function name is similar (just case differences) to other method/function of the same struct/file.
7473
func checkMethodName(holder string, id *ast.Ident, w *lintConfusingNames) {
74+
7575
if id.Name == "init" && holder == defaultStructName {
7676
// ignore init functions
7777
return
@@ -137,8 +137,11 @@ func getStructName(r *ast.FieldList) string {
137137

138138
t := r.List[0].Type
139139

140-
if p, _ := t.(*ast.StarExpr); p != nil { // if a pointer receiver => dereference pointer receiver types
141-
t = p.X
140+
switch v := t.(type) {
141+
case *ast.StarExpr:
142+
t = v.X
143+
case *ast.IndexExpr:
144+
t = v.X
142145
}
143146

144147
if p, _ := t.(*ast.Ident); p != nil {

testdata/confusing-naming1.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Test of confusing-naming rule.
2-
32
// Package pkg ...
43
package pkg
54

@@ -60,3 +59,14 @@ type tBar struct {
6059
qwe bool
6160
zxc float32
6261
}
62+
63+
// issue #864
64+
type x[T any] struct{}
65+
66+
func (x[T]) method() {
67+
}
68+
69+
type y[T any] struct{}
70+
71+
func (y[T]) method() {
72+
}

0 commit comments

Comments
 (0)