@@ -380,7 +380,7 @@ func (p *printer) parameters(fields *ast.FieldList, mode paramMode) {
380380 if closing := p .lineFor (fields .Closing ); 0 < prevLine && prevLine < closing {
381381 p .print (token .COMMA )
382382 p .linebreak (closing , 0 , ignore , true )
383- } else if mode == typeTParam && fields .NumFields () == 1 && combinesWithName (fields .List [0 ].Type ) {
383+ } else if mode == typeTParam && fields .NumFields () == 1 && combinesWithName (stripParensAlways ( fields .List [0 ].Type ) ) {
384384 // A type parameter list [P T] where the name P and the type expression T syntactically
385385 // combine to another valid (value) expression requires a trailing comma, as in [P *T,]
386386 // (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) {
398398 p .print (closeTok )
399399}
400400
401- // combinesWithName reports whether a name followed by the expression x
401+ // combinesWithName reports whether a name (*ast.Ident) followed by the expression x
402402// syntactically combines to another valid (value) expression. For instance
403403// using *T for x, "name *T" syntactically appears as the expression x*T.
404404// 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 {
411411 case * ast.BinaryExpr :
412412 return combinesWithName (x .X ) && ! isTypeElem (x .Y )
413413 case * ast.ParenExpr :
414- return combinesWithName (x .X )
414+ return ! isTypeElem (x .X )
415415 }
416416 return false
417417}
0 commit comments