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/go/analysis/passes/fieldalignment: runtime error: index out of range #43465

Closed
napei opened this issue Jan 2, 2021 · 8 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@napei
Copy link

napei commented Jan 2, 2021

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

$ go version
go version go1.15.6 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\natty\AppData\Local\go-build
set GOENV=C:\Users\natty\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\natty\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\natty\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\natty\Desktop\ent\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\natty\AppData\Local\Temp\go-build202576274=/tmp/go-build -gno-record-gcc-switches

What did you do?

Enabled the following config in vscode inside settings.json

  "gopls": {
    "analyses": {
      "fieldalignment": true
    },
    "usePlaceholders": true,
    "staticcheck": true
  },

gopls log: https://pastebin.com/raw/QmedfAZM

Log with trace enabled (not much different): https://pastebin.com/raw/6Zpm0VUw

What did you expect to see?

No errors, and fieldalignment should pick up on the following test struct

type test struct {
	field1 bool
	field2 float64
	field3 int32
}

What did you see instead?

Field alignment doesn't run when looking at source code inside a sub-folder/another package. When I add the above struct to a file in the root directory of the project, fieldalignment works fine, with hints on the struct.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 2, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jan 2, 2021
@stamblerre
Copy link
Contributor

/cc @leitzler for the panic

Field alignment doesn't run when looking at source code inside a sub-folder/another package. When I add the above struct to a file in the root directory of the project, fieldalignment works fine, with hints on the struct.

Can you give a repro example? Analysis only runs on packages with open files, so it's possible that's what you're seeing.

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 5, 2021
@leitzler
Copy link
Contributor

leitzler commented Jan 5, 2021

Yes, a repro would be helpful. This might be fixed already by CL 278372 that is merged to master but not 0.6.x.

@napei
Copy link
Author

napei commented Jan 6, 2021

Sorry, I should have done this to start with, I made a repro here https://github.com/napei/alignment-test
I noticed in a simple package with a main file and a sub package it works fine, but in this repro it doesn't.

A file to open for testing this would be ./ent/test.go, it's all generated code from ent which I use a lot, but I would assume it's all able to be linted without panicking.

This is typical of the codebase I'm working in at the moment, but that has about 40 more files in it.

I'll add that this also happens on WSL (linux) as well.

@napei
Copy link
Author

napei commented Jan 6, 2021

Analysis only runs on packages with open files, so it's possible that's what you're seeing.

@stamblerre I have specifically disabled file previews in vscode for that reason. I don't know why they thought that was a good feature 😄

"workbench.editor.enablePreviewFromQuickOpen": false,
"workbench.editor.enablePreview": false,

@napei
Copy link
Author

napei commented Jan 6, 2021

Oh interesting. When I embed a struct it panics.

Panic
type test struct {
	field1 bool
	field3 float64
	field2 int32
}


type Test struct {
	test 
	ID     int 
	Field1 bool 
	Field2 float64 
	Field3 int32
}
No Panic
type test struct {
	field1 bool
	field3 float64
	field2 int32
}


type Test struct {
	ID     int
	Field1 bool
	Field2 float64 
	Field3 int32 
}

Sorry for the comment spam

@leitzler
Copy link
Contributor

leitzler commented Jan 6, 2021

I tried your repro with CL 278372 applied and I'm not able to reproduce it.

@stamblerre
Copy link
Contributor

OK, so sounds like this is fixed at master. @napei, ok to close?

@napei
Copy link
Author

napei commented Jan 6, 2021

Sure. I'll wait for a release 🙂

@napei napei closed this as completed Jan 6, 2021
@golang golang locked and limited conversation to collaborators Jan 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants