Repository: mgechev/revive (go)

Issue:
Panic when contains empty type block declaration
**Describe the bug**
revive panics when the source code contains
`
type ()
`

**To Reproduce**
Steps to reproduce the behavior:
1. I install revive v1.2.4
2. Write Program with `type ()` declaration
3. Run `revive -config revive.toml -formatter friendly ./...`


Panic happened in the line:
github.com/mgechev/revive@v1.2.4/rule/redefines-builtin-id.go:92 

**Expected behavior**
Should not panics without any meaningful messages.


**Desktop (please complete the following information):**
 - OS: [e.g. Ubuntu 20.04]
 - go1.19.4 linux/amd64


Pull request description:
fix issue #792
Closes #792 


Patch:
diff --git a/rule/redefines-builtin-id.go b/rule/redefines-builtin-id.go
index 23dd85a..b3ff084 100644
--- a/rule/redefines-builtin-id.go
+++ b/rule/redefines-builtin-id.go
@@ -89,6 +89,9 @@ func (w *lintRedefinesBuiltinID) Visit(node ast.Node) ast.Visitor {
 	case *ast.GenDecl:
 		switch n.Tok {
 		case token.TYPE:
+			if len(n.Specs) < 1 {
+				return nil
+			}
 			typeSpec, ok := n.Specs[0].(*ast.TypeSpec)
 			if !ok {
 				return nil


Test patch:
diff --git a/testdata/redefines-builtin-id.go b/testdata/redefines-builtin-id.go
index 0593799..22e5975 100644
--- a/testdata/redefines-builtin-id.go
+++ b/testdata/redefines-builtin-id.go
@@ -29,3 +29,6 @@ var any int // MATCH /redefinition of the built-in type any/
 const any = 1 // MATCH /redefinition of the built-in type any/
 
 var i, copy int // MATCH /redefinition of the built-in function copy/
+
+// issue #792
+type ()