Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check param, result, type param of function in redefines-builtin-id rule #1023

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions rule/redefines-builtin-id.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,29 @@ func (w *lintRedefinesBuiltinID) Visit(node ast.Node) ast.Visitor {
if ok, bt := w.isBuiltIn(id); ok {
w.addFailure(n, fmt.Sprintf("redefinition of the built-in %s %s", bt, id))
}
case *ast.FuncType:
var fields []*ast.Field
if n.TypeParams != nil {
fields = append(fields, n.TypeParams.List...)
}
if n.Params != nil {
fields = append(fields, n.Params.List...)
}
if n.Results != nil {
fields = append(fields, n.Results.List...)
}
for _, field := range fields {
for _, name := range field.Names {
if obj := name.Obj; obj != nil {
if obj.Kind == ast.Var || obj.Kind == ast.Typ {
denisvmedia marked this conversation as resolved.
Show resolved Hide resolved
id := obj.Name
if ok, bt := w.isBuiltIn(id); ok {
w.addFailure(name, fmt.Sprintf("redefinition of the built-in %s %s", bt, id))
}
}
}
}
}
case *ast.AssignStmt:
for _, e := range n.Lhs {
id, ok := e.(*ast.Ident)
Expand Down
11 changes: 11 additions & 0 deletions testdata/redefines-builtin-id.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ var i, copy int // MATCH /redefinition of the built-in function copy/

// issue #792
type ()

func foo1(new int) { // MATCH /redefinition of the built-in function new/
_ = new
}

func foo2() (new int) { // MATCH /redefinition of the built-in function new/
return
}

func foo3[new any]() { // MATCH /redefinition of the built-in function new/
}
Loading