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

panic in checkUnaryExpr #3

Closed
choleraehyq opened this issue Jun 23, 2020 · 4 comments
Closed

panic in checkUnaryExpr #3

choleraehyq opened this issue Jun 23, 2020 · 4 comments
Assignees

Comments

@choleraehyq
Copy link
Contributor

➜  exportloopref ./...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x10eb0a9]

goroutine 6091 [running]:
go/ast.(*Object).Pos(0x0, 0xc002801aa0)
        /Users/cholerae/Documents/gopath/go1.15beta1/src/go/ast/scope.go:93 +0x29
github.com/kyoh86/exportloopref.(*Searcher).checkUnaryExpr(0xc008910bf8, 0xc002801ac0, 0xc0056ec500, 0xd, 0x10, 0x0, 0x12c4a01)
        /Users/cholerae/Documents/gocode/exportloopref/exportloopref.go:172 +0xbf
github.com/kyoh86/exportloopref.(*Searcher).Check(0xc008910bf8, 0x136b840, 0xc002801ac0, 0xc0056ec500, 0xd, 0x10, 0x0, 0x1)
        /Users/cholerae/Documents/gocode/exportloopref/exportloopref.go:71 +0xd1
github.com/kyoh86/exportloopref.run.func1(0x136b840, 0xc002801ac0, 0x1, 0xc0056ec500, 0xd, 0x10, 0x1)
        /Users/cholerae/Documents/gocode/exportloopref/exportloopref.go:43 +0x75
golang.org/x/tools/go/ast/inspector.(*Inspector).WithStack(0xc00891c380, 0xc008910c80, 0x5, 0x5, 0xc008910c08)
        /Users/cholerae/Documents/gopath/pkg/mod/golang.org/x/tools@v0.0.0-20200321224714-0d839f3cf2ed/go/ast/inspector/inspector.go:126 +0x142
github.com/kyoh86/exportloopref.run(0xc00891a5a0, 0xc0089164e0, 0x14d1cc0, 0xc008942388, 0xc0012d1dc0)
        /Users/cholerae/Documents/gocode/exportloopref/exportloopref.go:42 +0x273
golang.org/x/tools/go/analysis/internal/checker.(*action).execOnce(0xc0035defa0)
        /Users/cholerae/Documents/gopath/pkg/mod/golang.org/x/tools@v0.0.0-20200321224714-0d839f3cf2ed/go/analysis/internal/checker/checker.go:658 +0x75f
sync.(*Once).doSlow(0xc0035defa0, 0xc0012d1f90)
        /Users/cholerae/Documents/gopath/go1.15beta1/src/sync/once.go:66 +0xec
sync.(*Once).Do(...)
        /Users/cholerae/Documents/gopath/go1.15beta1/src/sync/once.go:57
golang.org/x/tools/go/analysis/internal/checker.(*action).exec(0xc0035defa0)
        /Users/cholerae/Documents/gopath/pkg/mod/golang.org/x/tools@v0.0.0-20200321224714-0d839f3cf2ed/go/analysis/internal/checker/checker.go:577 +0x65
golang.org/x/tools/go/analysis/internal/checker.execAll.func1(0xc0035defa0)
        /Users/cholerae/Documents/gopath/pkg/mod/golang.org/x/tools@v0.0.0-20200321224714-0d839f3cf2ed/go/analysis/internal/checker/checker.go:565 +0x34
created by golang.org/x/tools/go/analysis/internal/checker.execAll
        /Users/cholerae/Documents/gopath/pkg/mod/golang.org/x/tools@v0.0.0-20200321224714-0d839f3cf2ed/go/analysis/internal/checker/checker.go:571 +0x125
➜  exportloopref -V     
exportloopref: unsupported flag value: -V=true

I'm using 619c505 this version. My code itself can be compiled successfully but exportloopref panic. I'm trying to extract a minimal production.

@dgryski
Copy link

dgryski commented Jun 23, 2020

Maybe try https://github.com/mvdan/goreduce ?

@choleraehyq
Copy link
Contributor Author

@kyoh86 I've found a minimal production.

package main

import "encoding/binary"

func main() {
	for i := 0; i < 10; i++ {
		println(&binary.BigEndian)
	}
}

Run exportloopref on this code will cause panic.
The reason of panic is, a package name ast.Ident has a nil Obj. So binary.BigEndian will be parse to

*ast.SelectorExpr {
   105  .  .  .  .  .  .  .  .  .  .  .  .  .  X: *ast.Ident {
   106  .  .  .  .  .  .  .  .  .  .  .  .  .  .  NamePos: 8:12
   107  .  .  .  .  .  .  .  .  .  .  .  .  .  .  Name: "binary"
   108  .  .  .  .  .  .  .  .  .  .  .  .  .  }
   109  .  .  .  .  .  .  .  .  .  .  .  .  .  Sel: *ast.Ident {
   110  .  .  .  .  .  .  .  .  .  .  .  .  .  .  NamePos: 8:19
   111  .  .  .  .  .  .  .  .  .  .  .  .  .  .  Name: "BigEndian"
   112  .  .  .  .  .  .  .  .  .  .  .  .  .  }
   113  .  .  .  .  .  .  .  .  .  .  .  .  }

which will cause panic.

@kyoh86
Copy link
Owner

kyoh86 commented Jun 24, 2020

@choleraehyq thank you for your contribution.
I'll tag it if the CI finished.

@kyoh86 kyoh86 self-assigned this Jun 24, 2020
@kyoh86
Copy link
Owner

kyoh86 commented Jun 24, 2020

@kyoh86 kyoh86 closed this as completed Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants