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

x/tools/cmd/goimports: does not handle package unsafe properly #14966

Closed
pborman opened this issue Mar 25, 2016 · 2 comments
Closed

x/tools/cmd/goimports: does not handle package unsafe properly #14966

pborman opened this issue Mar 25, 2016 · 2 comments

Comments

@pborman
Copy link
Contributor

pborman commented Mar 25, 2016

Please answer these questions before submitting your issue. Thanks!

I believe goimports does not automatically include package unsafe even if referenced in the source, which is fine, but when package unsafe is imported it can confuse goimports and produces syntactically correct, but unexpected output, such as:

import (
    "reflect"
    "unsafe"
)
import "fmt"
  1. What version of Go are you using (go version)?
go version go1.6 linux/amd64
  1. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GORACE=""
GOROOT="/usr/lib/google-golang"
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -gno-record-gcc-switches -fdebug-prefix-map=/tmp/go-build262021310=/tmp/go-build"
CXX="g++"
CGO_ENABLED="1"
  1. What did you do?

Ran goimports on the source code http://play.golang.org/p/Ppc325UINU

package code

import "unsafe"
import "fmt"

var _ = fmt.Print
var _ = unsafe.Sizeof
var _ = reflect.Value
  1. What did you expect to see?

http://play.golang.org/p/ySR9QrdVlp

package code

import (
    "fmt"
    "reflect"
    "unsafe"
)

var _ = fmt.Print
var _ = unsafe.Sizeof
var _ = reflect.Value
  1. What did you see instead?

http://play.golang.org/p/i49dfImPxA

package code

import (
    "reflect"
    "unsafe"
)
import "fmt"

var _ = fmt.Print
var _ = unsafe.Sizeof
var _ = reflect.Value
@ianlancetaylor ianlancetaylor changed the title goimports does not handle package unsafe properly x/tools/cmd/goimports: does not handle package unsafe properly Mar 25, 2016
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Mar 25, 2016
@ianlancetaylor
Copy link
Contributor

CC @bradfitz

@davidrjenni
Copy link
Contributor

This is a duplicate of #14075.
There is a fix waiting for review: https://golang.org/cl/19828.

@golang golang locked and limited conversation to collaborators Mar 28, 2017
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

5 participants