From 7dda2f5e14eb08c636277bc83ff48ebc32938b69 Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Fri, 6 Sep 2024 11:02:37 +0200 Subject: [PATCH 1/2] go/printer: check whether !isTypeElem, instead of combinesWithNam --- src/go/printer/nodes.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/go/printer/nodes.go b/src/go/printer/nodes.go index 780d58ec5c141..edb25218a8c6f 100644 --- a/src/go/printer/nodes.go +++ b/src/go/printer/nodes.go @@ -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 @@ -398,7 +398,7 @@ func (p *printer) parameters(fields *ast.FieldList, mode paramMode) { p.print(closeTok) } -// combinesWithName reports whether a name followed by the expression x +// combinesWithName reports whether a name (*ast.Ident) followed by the expression x // syntactically combines to another valid (value) expression. For instance // using *T for x, "name *T" syntactically appears as the expression x*T. // On the other hand, using P|Q or *P|~Q for x, "name P|Q" or name *P|~Q" @@ -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 } From 37993b5baf11f83e8fb9428981965f2d964cddf3 Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Fri, 6 Sep 2024 18:22:08 +0200 Subject: [PATCH 2/2] update Change-Id: Ib5162a6162d9f396c4da99c590e2544a174fb4d3 --- src/go/printer/nodes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/go/printer/nodes.go b/src/go/printer/nodes.go index edb25218a8c6f..38d6f62a95cd2 100644 --- a/src/go/printer/nodes.go +++ b/src/go/printer/nodes.go @@ -398,7 +398,7 @@ func (p *printer) parameters(fields *ast.FieldList, mode paramMode) { p.print(closeTok) } -// combinesWithName reports whether a name (*ast.Ident) followed by the expression x +// combinesWithName reports whether a name followed by the expression x // syntactically combines to another valid (value) expression. For instance // using *T for x, "name *T" syntactically appears as the expression x*T. // On the other hand, using P|Q or *P|~Q for x, "name P|Q" or name *P|~Q"