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

fix: extend support of parenthesized expression as receiver #79

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,15 +908,20 @@ func recvPrefix(recv *ast.FieldList) string {
}
expr = star.X
}

return identName(expr)
}

func identName(expr ast.Expr) string {
switch expr := expr.(type) {
case *ast.Ident:
return expr.Name + "."
case *ast.IndexExpr:
return expr.X.(*ast.Ident).Name + "."
return identName(expr.X)
case *ast.ParenExpr:
return expr.X.(*ast.Ident).Name + "."
return identName(expr.X)
case *ast.IndexListExpr:
return expr.X.(*ast.Ident).Name + "."
return identName(expr.X)
default:
panic(fmt.Sprintf("unexpected receiver AST node: %T", expr))
}
Expand Down
6 changes: 6 additions & 0 deletions testdata/script/parenthesized_expression.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module testdata.tld/foo
go 1.18
-- stdout.golden --
foo.go:7:37: (*FooType).multImplsMethod - a is unused
foo.go:12:44: (*FooType).multImplsMethod2 - a is unused
-- foo.go --
package foo

Expand All @@ -18,3 +19,8 @@ func (f *(FooType)) multImplsMethod(a int) int64 {
DoWork()
return 3
}

func (f *((((FooType))))) multImplsMethod2(a int) int64 {
DoWork()
return 3
}