Skip to content

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

@pborman

Description

@pborman

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions