From e2db3c4732d8bb32ec32b3134e97a36be4c09620 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Tue, 28 May 2024 15:01:48 +0200 Subject: [PATCH] support multiple parentheses in receiver type expressions (#79) --- check/check.go | 11 ++++++++--- testdata/script/parenthesized_expression.txtar | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/check/check.go b/check/check.go index b1704e4..2bda013 100644 --- a/check/check.go +++ b/check/check.go @@ -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)) } diff --git a/testdata/script/parenthesized_expression.txtar b/testdata/script/parenthesized_expression.txtar index b544387..cdaf8be 100644 --- a/testdata/script/parenthesized_expression.txtar +++ b/testdata/script/parenthesized_expression.txtar @@ -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 @@ -18,3 +19,8 @@ func (f *(FooType)) multImplsMethod(a int) int64 { DoWork() return 3 } + +func (f *((((FooType))))) multImplsMethod2(a int) int64 { + DoWork() + return 3 +}