Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2b81ca8

Browse files
committed
fix: support any
1 parent27114bd commit2b81ca8

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

‎pkg/analyzer/analyzer.go‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var Analyzer = &analysis.Analyzer{
1616
Requires: []*analysis.Analyzer{inspect.Analyzer},
1717
}
1818

19-
funcrun(pass*analysis.Pass) (interface{},error) {
19+
funcrun(pass*analysis.Pass) (any,error) {
2020
insp:=pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
2121

2222
nodeFilter:= []ast.Node{
@@ -50,19 +50,15 @@ func run(pass *analysis.Pass) (interface{}, error) {
5050
}
5151

5252
argsParamType,ok:=params[len(params)-1].Type.(*ast.Ellipsis)
53-
if!ok {// args are not ellipsis (...args)
53+
if!ok {
54+
// args are not ellipsis (...args)
5455
return
5556
}
5657

57-
elementType,ok:=argsParamType.Elt.(*ast.InterfaceType)
58-
if!ok {// args are not of interface type, but we need interface{}
58+
if!isAny(argsParamType) {
5959
return
6060
}
6161

62-
ifelementType.Methods!=nil&&len(elementType.Methods.List)!=0 {
63-
return// has >= 1 method in interface, but we need an empty interface "interface{}"
64-
}
65-
6662
ifstrings.HasSuffix(funcDecl.Name.Name,"f") {
6763
return
6864
}
@@ -73,3 +69,22 @@ func run(pass *analysis.Pass) (interface{}, error) {
7369

7470
returnnil,nil
7571
}
72+
73+
funcisAny(ell*ast.Ellipsis)bool {
74+
switchelt:=ell.Elt.(type) {
75+
case*ast.InterfaceType:
76+
ifelt.Methods!=nil&&len(elt.Methods.List)!=0 {
77+
// has >= 1 method in interface, but we need an empty interface "interface{}"
78+
returnfalse
79+
}
80+
81+
returntrue
82+
83+
case*ast.Ident:
84+
ifelt.Name=="any" {
85+
returntrue
86+
}
87+
}
88+
89+
returnfalse
90+
}

‎testdata/src/p/p.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ func prinfLikeFunc(format string, args ...interface{}) {} // want "printf-like f
2828
funcprinfLikeFuncWithExtraArgs1(extraArg,formatstring,args...interface{}) {}// want "printf-like formatting function"
2929

3030
funcprinfLikeFuncWithExtraArgs2(extraArgint,formatstring,args...interface{}) {}// want "printf-like formatting function"
31+
32+
funcprinfLikeFuncAny(formatstring,args...any) {}// want "printf-like formatting function"
33+
34+
funcprinfLikeFuncWithExtraArgs1Any(extraArg,formatstring,args...any) {}// want "printf-like formatting function"
35+
36+
funcprinfLikeFuncWithExtraArgs2Any(extraArgint,formatstring,args...any) {}// want "printf-like formatting function"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp