Skip to content

x/tools/cmd/goimports: panic on reading from stdin on Windows #20941

@nasitra

Description

@nasitra

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

1.8.3

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

windows/amd64

What did you do?

Make the code(hello.go) without importing 'fmt' package

package main

func main() {
  fmt.Println("hello")
}

Then run goimports reading the code from stdin

type hello.go | goimports

What did you expect to see?

Output code text with importing 'fmt' package

package main

import "fmt"

func main() {
        fmt.Println("hello")
}

What did you see instead?

Runtime error occurred.

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x8 pc=0x5a2dc1]

goroutine 18 [running]:
golang.org/x/tools/imports.fixImports.func2(0xc04205a0c8, 0xc04202ec00, 0x616eb5, 0x10, 0xc0420311e4, 0x3, 0xc042058e70)
        C:/XXX/go/src/golang.org/x/tools/imports/fix.go:257 +0x41
created by golang.org/x/tools/imports.fixImports
        C:/XXX/go/src/golang.org/x/tools/imports/fix.go:268 +0x676

Because of the error, I can't use goimports in GoSublime for Sublime Text 3 on Windows.

I tried the local change (it works), but it seems that this problem is caused by a different result of dirPackageInfoFile() for stdin between Windows and other platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions