From 099b387be8e3b1d2ad8854cca48c7cc7b54f137e Mon Sep 17 00:00:00 2001 From: visualfc Date: Thu, 26 Oct 2023 15:41:33 +0800 Subject: [PATCH 1/2] checkParenExpr: check ast.SelectorExpr --- ast.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ast.go b/ast.go index 43d818c4..7e156370 100644 --- a/ast.go +++ b/ast.go @@ -871,8 +871,11 @@ func isPointer(typ types.Type) bool { } func checkParenExpr(x ast.Expr) ast.Expr { - if _, ok := x.(*ast.CompositeLit); ok { + switch v := x.(type) { + case *ast.CompositeLit: return &ast.ParenExpr{X: x} + case *ast.SelectorExpr: + v.X = checkParenExpr(v.X) } return x } From 461b14dafb285636ce8d322fc1c808afbd88c1f0 Mon Sep 17 00:00:00 2001 From: visualfc Date: Thu, 26 Oct 2023 15:44:32 +0800 Subject: [PATCH 2/2] TestCheckParenExpr --- builtin_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builtin_test.go b/builtin_test.go index 457c022c..e150d49a 100644 --- a/builtin_test.go +++ b/builtin_test.go @@ -601,6 +601,10 @@ func TestCheckParenExpr(t *testing.T) { if _, ok := x.(*ast.ParenExpr); !ok { t.Fatal("TestCheckParenExpr failed:", x) } + x = checkParenExpr(&ast.SelectorExpr{X: &ast.CompositeLit{}, Sel: ast.NewIdent("sel")}) + if _, ok := x.(*ast.SelectorExpr).X.(*ast.ParenExpr); !ok { + t.Fatal("TestCheckParenExpr failed:", x) + } } func TestNoFuncName(t *testing.T) {