@@ -319,9 +319,17 @@ func (p *printer) exprList(prev0 token.Pos, list []ast.Expr, depth int, mode exp
319
319
}
320
320
}
321
321
322
- func (p * printer ) parameters (fields * ast.FieldList , isTypeParam bool ) {
322
+ type paramMode int
323
+
324
+ const (
325
+ funcParam paramMode = iota
326
+ funcTParam
327
+ typeTParam
328
+ )
329
+
330
+ func (p * printer ) parameters (fields * ast.FieldList , mode paramMode ) {
323
331
openTok , closeTok := token .LPAREN , token .RPAREN
324
- if isTypeParam {
332
+ if mode != funcParam {
325
333
openTok , closeTok = token .LBRACK , token .RBRACK
326
334
}
327
335
p .print (fields .Opening , openTok )
@@ -373,7 +381,7 @@ func (p *printer) parameters(fields *ast.FieldList, isTypeParam bool) {
373
381
if closing := p .lineFor (fields .Closing ); 0 < prevLine && prevLine < closing {
374
382
p .print (token .COMMA )
375
383
p .linebreak (closing , 0 , ignore , true )
376
- } else if isTypeParam && fields .NumFields () == 1 {
384
+ } else if mode == typeTParam && fields .NumFields () == 1 {
377
385
// Otherwise, if we are in a type parameter list that could be confused
378
386
// with the constant array length expression [P*C], print a comma so that
379
387
// parsing is unambiguous.
@@ -411,10 +419,10 @@ func isTypeLit(x ast.Expr) bool {
411
419
412
420
func (p * printer ) signature (sig * ast.FuncType ) {
413
421
if sig .TypeParams != nil {
414
- p .parameters (sig .TypeParams , true )
422
+ p .parameters (sig .TypeParams , funcTParam )
415
423
}
416
424
if sig .Params != nil {
417
- p .parameters (sig .Params , false )
425
+ p .parameters (sig .Params , funcParam )
418
426
} else {
419
427
p .print (token .LPAREN , token .RPAREN )
420
428
}
@@ -428,7 +436,7 @@ func (p *printer) signature(sig *ast.FuncType) {
428
436
p .expr (stripParensAlways (res .List [0 ].Type ))
429
437
return
430
438
}
431
- p .parameters (res , false )
439
+ p .parameters (res , funcParam )
432
440
}
433
441
}
434
442
@@ -1639,7 +1647,7 @@ func (p *printer) spec(spec ast.Spec, n int, doIndent bool) {
1639
1647
p .setComment (s .Doc )
1640
1648
p .expr (s .Name )
1641
1649
if s .TypeParams != nil {
1642
- p .parameters (s .TypeParams , true )
1650
+ p .parameters (s .TypeParams , typeTParam )
1643
1651
}
1644
1652
if n == 1 {
1645
1653
p .print (blank )
@@ -1829,7 +1837,7 @@ func (p *printer) funcDecl(d *ast.FuncDecl) {
1829
1837
// FUNC is emitted).
1830
1838
startCol := p .out .Column - len ("func " )
1831
1839
if d .Recv != nil {
1832
- p .parameters (d .Recv , false ) // method: print receiver
1840
+ p .parameters (d .Recv , funcParam ) // method: print receiver
1833
1841
p .print (blank )
1834
1842
}
1835
1843
p .expr (d .Name )
0 commit comments