1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:44:39 -07:00

go/printer: check whether !isTypeElem, instead of combinesWithName when ParenExpr

See discussion in CL 610115 and CL 610758.

For #69206

Change-Id: I16f394cb3440106650fb64a466f2723a4dba3871
GitHub-Last-Rev: 37993b5baf
GitHub-Pull-Request: golang/go#69309
Reviewed-on: https://go-review.googlesource.com/c/go/+/611355
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
Mateusz Poliwczak 2024-09-06 16:28:20 +00:00 committed by Gopher Robot
parent 42d1f08cbb
commit 464aae706b

View File

@ -380,7 +380,7 @@ func (p *printer) parameters(fields *ast.FieldList, mode paramMode) {
if closing := p.lineFor(fields.Closing); 0 < prevLine && prevLine < closing {
p.print(token.COMMA)
p.linebreak(closing, 0, ignore, true)
} else if mode == typeTParam && fields.NumFields() == 1 && combinesWithName(fields.List[0].Type) {
} else if mode == typeTParam && fields.NumFields() == 1 && combinesWithName(stripParensAlways(fields.List[0].Type)) {
// A type parameter list [P T] where the name P and the type expression T syntactically
// combine to another valid (value) expression requires a trailing comma, as in [P *T,]
// (or an enclosing interface as in [P interface(*T)]), so that the type parameter list
@ -411,7 +411,7 @@ func combinesWithName(x ast.Expr) bool {
case *ast.BinaryExpr:
return combinesWithName(x.X) && !isTypeElem(x.Y)
case *ast.ParenExpr:
return combinesWithName(x.X)
return !isTypeElem(x.X)
}
return false
}