Skip to content

Commit

Permalink
Merge pull request #295 from visualfc/check_parent
Browse files Browse the repository at this point in the history
checkParenExpr: check ast.SelectorExpr
  • Loading branch information
xushiwei authored Oct 26, 2023
2 parents 08fb252 + 461b14d commit 48d24f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 48d24f4

Please sign in to comment.