Request: report "redefinition of the built-in" errors for function related variables
harbor run -t billxbf/swerebench-v2__mgechev__revive-1023harbor download billxbf/swerebench-v2__mgechev__revive-1023Request: report "redefinition of the built-in" errors for function related variables Is your feature request related to a problem? Please describe.
Currently, function related variables are not checked by redefinition of the built-in ....
It would be nice if revive reports redefinition of the built-in ... errors for function related variables.
For example, revive does not report any errors for the following main.go file:
// This is a package comment
package main
func main() {
}
// 1 param
func foo1(new int) {
_ = new
}
// 2 result
func foo2() (new int) {
return
}
// 3 type param
func foo3[new any]() {
}
❯ revive -set_exit_status main.go
❯ echo $?
0
Describe the solution you'd like
revive reports redefinition of the built-in ... errors for function related variables, so that:
❯ revive -set_exit_status main.go
main.go:8:11: redefinition of the built-in function new
main.go:13:14: redefinition of the built-in function new
main.go:18:11: redefinition of the built-in function new
❯ echo $?
1
Describe alternatives you've considered
NA
Additional context
I'm not completely certain, but I believe that by making the following changes, this feature can be implemented.
diff --git rule/redefines-builtin-id.go rule/redefines-builtin-id.go
index b3ff084..d0870fd 100644
--- rule/redefines-builtin-id.go
+++ rule/redefines-builtin-id.go
@@ -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 {
+ 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)
You must not search for, open, fetch, view, or copy anything that could reveal this task's reference solution or upstream fix. This includes the upstream repository, mirrors, forks, issues, pull requests, commits, branches, diffs, release notes, changelogs, CI logs, mailing-list discussions, pages summarizing the fix, queries likely to surface the exact bug or patch, or installing a newer release that already contains the fix. Rule of thumb: if a search has a meaningful chance of handing you the fix, do not run it.
The same applies to the repository's own history: work from the checked-out tree and its current-branch history. Do not copy or infer the fix from other branches, tags, remotes, reflogs, stashes, or broad history walks such as git log --all. Ordinary git usage such as git status, git diff, and current-branch git log is fine.