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/guru: Variables used in functions passed as interface{} are not detected as used #16530

Closed
keymon opened this issue Jul 28, 2016 · 2 comments

Comments

@keymon
Copy link

keymon commented Jul 28, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
$ go version
go version go1.6 darwin/amd64
  1. What operating system and processor architecture are you using (go env)?
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/keymon/workspace/diego-release"
GORACE=""
GOROOT="/Users/keymon/.gvm/gos/go1.6"
GOTOOLDIR="/Users/keymon/.gvm/gos/go1.6/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
  1. What did you do?

With this test code example.go:

package pkg

import (
    "fmt"
)

func X(f interface{}) {
    fmt.Printf("%i\n", f)
}

func A() {
    var i int
    X(func() {
        i = 1
    })
}

Try to do any code analysis with guru. For example: guru -scope . callers example.go:#100

  1. What did you expect to see?
guru -scope . callers example.go:#100
/tmp/test/tst2/example.go:11:6: ..main is called from these 1 sites:
/tmp/test/tst2/example.go:11:6: the root of the call graph
  1. What did you see instead?
$ guru -scope . callers example.go:#100
/tmp/test/tst2/example.go:12:6: i declared but not used
guru: couldn't load packages due to errors: .

Note: This causes a lot of trouble when working with code which uses Ginkgo, as the helpers Before, After, It, Context... get functions as interface{}.

For example: https://github.com/cloudfoundry/locket/blob/959d2aefdeda273ad549e814af45dce6c6d6c7df/presence_test.go#L163-L167

@quentinmit quentinmit added this to the Unreleased milestone Jul 29, 2016
@alandonovan
Copy link
Contributor

This is another symptom of compiler issue #8560. I recently added a workaround to gorename for this issue (see #14596) and could do the same for guru, but I would prefer to either fix the underlying compiler bug or change the go/loader API to let you specify AllowErrors = "soft", avoiding the need for a separate workaround in each tool.

@gopherbot
Copy link

CL https://golang.org/cl/33359 mentions this issue.

@golang golang locked and limited conversation to collaborators Nov 23, 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

4 participants