Skip to content

Commit

Permalink
fix: extend support of parenthesized expression as receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Apr 28, 2024
1 parent 063aff9 commit 4fa02a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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
}

0 comments on commit 4fa02a8

Please sign in to comment.