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/format: doesn't format source when source has comment after package name #26931

Closed
wingyplus opened this issue Aug 11, 2018 · 4 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@wingyplus
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +479da24aac Fri Aug 10 00:47:31 2018 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes, it does.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/wingyplus/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/wingyplus/gopath"
GOPROXY=""
GORACE=""
GOROOT="/Users/wingyplus/go/go"
GOTMPDIR=""
GOTOOLDIR="/Users/wingyplus/go/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dj/kszxmd1d1lbf7g34gxsb3v980000gn/T/go-build172215713=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I try to investigate the problem on #26921. And found format.Source is wrong behaviour. The reproduce source is:

package main

import (
	"fmt"
	"go/format"
	"log"
)

const src = `package main // comment
import "fmt"

// T does something useful.
func T() {
  var _ = fmt.Printf
}
`

func main() {
	out, err := format.Source([]byte(src))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(out))
}

What did you expect to see?

package main // comment

import "fmt"

// T does something useful.
func T() {
	var _ = fmt.Printf
}

What did you see instead?

package main // comment
import "fmt"

// T does something useful.
func T() {
	var _ = fmt.Printf
}
@myitcv
Copy link
Member

myitcv commented Aug 11, 2018

cc @mvdan @griesemer

@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 11, 2018
@bcmills bcmills added this to the Go1.11 milestone Aug 11, 2018
@bcmills
Copy link
Contributor

bcmills commented Aug 11, 2018

Possibly related to #26930?

@agnivade
Copy link
Contributor

I think this is dup of #22631. This has been like this since 1.9.

@mvdan
Copy link
Member

mvdan commented Aug 11, 2018

Indeed a duplicate, and likely not a regression in 1.11.

@mvdan mvdan closed this as completed Aug 11, 2018
@golang golang locked and limited conversation to collaborators Aug 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants