Skip to content

Commit

Permalink
go/printer: check whether !isTypeElem, instead of combinesWithName wh…
Browse files Browse the repository at this point in the history
…en ParenExpr

See discussion in CL 610115 and CL 610758.

For #69206

Change-Id: I16f394cb3440106650fb64a466f2723a4dba3871
GitHub-Last-Rev: 37993b5
GitHub-Pull-Request: #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>
  • Loading branch information
mateusz834 authored and gopherbot committed Sep 6, 2024
1 parent 42d1f08 commit 464aae7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/go/printer/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 464aae7

Please sign in to comment.