Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/printer: spurious , inserted after ... argument #4533

Closed
rsc opened this issue Dec 12, 2012 · 2 comments
Closed

go/printer: spurious , inserted after ... argument #4533

rsc opened this issue Dec 12, 2012 · 2 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Dec 12, 2012

Has something to do with the input being multiline.

$ cat x.go
package main

func f(...interface{})
func (t *T) f(...interface{})

func f1(...interface{m();n()})
func (t *T) f1(...interface{m();n()})

$ gofmt x.go
package main

func f(...interface{})
func (t *T) f(...interface{})

func f1(...interface {
    m()
    n()
})
func (t *T) f1(...interface {
    m()
    n()
})

(So far so good!)

$ gofmt x.go | gofmt
package main

func f(...interface{})
func (t *T) f(...interface{})

func f1(...interface {
    m()
    n()
},)
func (t *T) f1(...interface {
    m()
    n()
},)

Oops, this time we got some extra commas.

6g rejects this last version, because the ... must be last. If the trailing comma is
allowed, which I think it is, then that's a bug in 6g too. Will file a different bug for
that.
@griesemer
Copy link
Contributor

Comment 1:

This is unrelated to ... . It's simply an idempotency issue. The following programs show
the same behavior:
cat x.go:
package main
func f0(interface{})
func f1(interface{m()})
cat x.go | gofmt
package main
func f0(interface{})
func f1(interface {
    m()
})
cat x.go | gofmt | gofmt
package main
func f0(interface{})
func f1(interface {
    m()
},)
and:
cat x.go
package main
func f0(struct{})
func f1(struct{x int; y int})
cat x.go | gofmt
package main
func f0(struct{})
func f1(struct {
    x int
    y int
})
cat x.go | gofmt | gofmt
package main
func f0(struct{})
func f1(struct {
    x int
    y int
},)
The resulting program is not incorrect: parameters may always end in a comma
(http://tip.golang.org/ref/spec#Parameters).

@griesemer
Copy link
Contributor

Comment 2:

This issue was closed by revision 8323cef.

Status changed to Fixed.

@rsc rsc added fixed labels Mar 12, 2013
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants