@@ -380,7 +380,7 @@ func (p *printer) parameters(fields *ast.FieldList, mode paramMode) {
380
380
if closing := p .lineFor (fields .Closing ); 0 < prevLine && prevLine < closing {
381
381
p .print (token .COMMA )
382
382
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 ) ) {
384
384
// A type parameter list [P T] where the name P and the type expression T syntactically
385
385
// combine to another valid (value) expression requires a trailing comma, as in [P *T,]
386
386
// (or an enclosing interface as in [P interface(*T)]), so that the type parameter list
@@ -401,7 +401,7 @@ func (p *printer) parameters(fields *ast.FieldList, mode paramMode) {
401
401
// combinesWithName reports whether a name followed by the expression x
402
402
// syntactically combines to another valid (value) expression. For instance
403
403
// using *T for x, "name *T" syntactically appears as the expression x*T.
404
- // On the other hand, using P|Q or *P|~Q for x, "name P|Q" or name *P|~Q"
404
+ // On the other hand, using P|Q or *P|~Q for x, "name P|Q" or " name *P|~Q"
405
405
// cannot be combined into a valid (value) expression.
406
406
func combinesWithName (x ast.Expr ) bool {
407
407
switch x := x .(type ) {
@@ -411,9 +411,7 @@ func combinesWithName(x ast.Expr) bool {
411
411
case * ast.BinaryExpr :
412
412
return combinesWithName (x .X ) && ! isTypeElem (x .Y )
413
413
case * ast.ParenExpr :
414
- // name(x) combines but we are making sure at
415
- // the call site that x is never parenthesized.
416
- panic ("unexpected parenthesized expression" )
414
+ return ! isTypeElem (x .X )
417
415
}
418
416
return false
419
417
}
0 commit comments