mirror of
https://github.com/golang/go
synced 2024-11-14 06:00:22 -07:00
go/parser: convert CallExpr into ParenExpr in extractName
This commit is contained in:
parent
a4eba85fad
commit
9162984fe9
@ -2667,8 +2667,8 @@ func (p *parser) parseTypeSpec(doc *ast.CommentGroup, _ token.Token, _ int) ast.
|
||||
// P*[]int T/F P *[]int
|
||||
// P*E T P *E
|
||||
// P*E F nil P*E
|
||||
// P([]int) T/F P []int
|
||||
// P(E) T P E
|
||||
// P([]int) T/F P ([]int)
|
||||
// P(E) T P (E)
|
||||
// P(E) F nil P(E)
|
||||
// P*E|F|~G T/F P *E|F|~G
|
||||
// P*E|F|G T P *E|F|G
|
||||
@ -2695,8 +2695,11 @@ func extractName(x ast.Expr, force bool) (*ast.Ident, ast.Expr) {
|
||||
case *ast.CallExpr:
|
||||
if name, _ := x.Fun.(*ast.Ident); name != nil {
|
||||
if len(x.Args) == 1 && x.Ellipsis == token.NoPos && (force || isTypeElem(x.Args[0])) {
|
||||
// x = name "(" x.ArgList[0] ")"
|
||||
return name, x.Args[0]
|
||||
return name, &ast.ParenExpr{
|
||||
Lparen: x.Lparen,
|
||||
X: x.Args[0],
|
||||
Rparen: x.Rparen,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -821,3 +821,18 @@ func TestIssue57490(t *testing.T) {
|
||||
t.Fatalf("offset = %d, want %d", offset, tokFile.Size())
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTypeParamsAsParenExpr(t *testing.T) {
|
||||
const src = "package p\ntype X[A (B),] struct{}"
|
||||
|
||||
fs := token.NewFileSet()
|
||||
f, err := ParseFile(fs, "test.go", src, ParseComments|SkipObjectResolution)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
typeParam := f.Decls[0].(*ast.GenDecl).Specs[0].(*ast.TypeSpec).TypeParams.List[0].Type
|
||||
_, ok := typeParam.(*ast.ParenExpr)
|
||||
if !ok {
|
||||
t.Fatalf("typeParam is a %T; want: *ast.ParenExpr", typeParam)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user