Commit 8323cef7 authored by Robert Griesemer's avatar Robert Griesemer

go/printer, gofmt: avoid extra final comma in multi-line signatures

The parameter list layout function was incorrectly computing the
end of the previous line in cases where a parameter type spanned
multiple lines. As a result, an extra (valid, but not needed)
comma was introduced before the paremeter list's closing parenthesis.

Fixes #4533.

R=rsc
CC=golang-dev
https://golang.org/cl/7674044
parent d8253205
......@@ -271,12 +271,12 @@ func (p *printer) parameters(fields *ast.FieldList) {
// if there are multiple parameter names for this par
// or the type is on a separate line)
var parLineBeg int
var parLineEnd = p.lineFor(par.Type.Pos())
if len(par.Names) > 0 {
parLineBeg = p.lineFor(par.Names[0].Pos())
} else {
parLineBeg = parLineEnd
parLineBeg = p.lineFor(par.Type.Pos())
}
var parLineEnd = p.lineFor(par.Type.End())
// separating "," if needed
needsLinebreak := 0 < prevLine && prevLine < parLineBeg
if i > 0 {
......
......@@ -912,3 +912,28 @@ func _(x chan (<-chan int))
func _(x chan<- (chan int))
func _(x chan<- (chan int))
func _(x chan<- (chan int))
// don't introduce comma after last parameter if the closing ) is on the same line
// even if the parameter type itself is multi-line (test cases from issue 4533)
func _(...interface{})
func _(...interface {
m()
n()
}) // no extra comma between } and )
func (t *T) _(...interface{})
func (t *T) _(...interface {
m()
n()
}) // no extra comma between } and )
func _(interface{})
func _(interface {
m()
}) // no extra comma between } and )
func _(struct{})
func _(struct {
x int
y int
}) // no extra comma between } and )
......@@ -921,3 +921,28 @@ func _(x ((((chan(<-chan int))))))
func _(x chan<-(chan int))
func _(x (chan<-(chan int)))
func _(x ((((chan<-(chan int))))))
// don't introduce comma after last parameter if the closing ) is on the same line
// even if the parameter type itself is multi-line (test cases from issue 4533)
func _(...interface{})
func _(...interface {
m()
n()
}) // no extra comma between } and )
func (t *T) _(...interface{})
func (t *T) _(...interface {
m()
n()
}) // no extra comma between } and )
func _(interface{})
func _(interface {
m()
}) // no extra comma between } and )
func _(struct{})
func _(struct {
x int
y int
}) // no extra comma between } and )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment