Skip to content

Commit

Permalink
support method receivers with type parameters for Go 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
fzipp committed Oct 30, 2021
1 parent e117b7f commit 44804ba
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
12 changes: 0 additions & 12 deletions analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,3 @@ func funcName(fn *ast.FuncDecl) string {
}
return fn.Name.Name
}

// recvString returns a string representation of recv of the
// form "T", "*T", or "BADRECV" (if not a proper receiver type).
func recvString(recv ast.Expr) string {
switch t := recv.(type) {
case *ast.Ident:
return t.Name
case *ast.StarExpr:
return "*" + recvString(t.X)
}
return "BADRECV"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/fzipp/gocyclo

go 1.16
go 1.18
26 changes: 26 additions & 0 deletions recv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2021 Frederik Zipp. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.18
// +build go1.18

package gocyclo

import "go/ast"

// recvString returns a string representation of recv of the
// form "T", "*T", or "BADRECV" (if not a proper receiver type).
func recvString(recv ast.Expr) string {
switch t := recv.(type) {
case *ast.Ident:
return t.Name
case *ast.StarExpr:
return "*" + recvString(t.X)
case *ast.IndexExpr:
return recvString(t.X)
case *ast.IndexListExpr:
return recvString(t.X)
}
return "BADRECV"
}
24 changes: 24 additions & 0 deletions recv_pre118.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2021 Frederik Zipp. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !go1.18
// +build !go1.18

package gocyclo

import "go/ast"

// recvString returns a string representation of recv of the
// form "T", "*T", or "BADRECV" (if not a proper receiver type).
func recvString(recv ast.Expr) string {
switch t := recv.(type) {
case *ast.Ident:
return t.Name
case *ast.StarExpr:
return "*" + recvString(t.X)
case *ast.IndexExpr:
return recvString(t.X)
}
return "BADRECV"
}

0 comments on commit 44804ba

Please sign in to comment.