Go: x/tools/cmd/gorename: gorename fails with on cgo-using files

Created on 22 May 2016  路  3Comments  路  Source: golang/go

Please answer these questions before submitting your issue. Thanks!

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

go version go1.6 darwin/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ash/code/go"
GORACE=""
GOROOT="/Users/ash/.homebrew/Cellar/go/1.6/libexec"
GOTOOLDIR="/Users/ash/.homebrew/Cellar/go/1.6/libexec/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"

3. What did you do?

Given this input file demo.go:

package main

// #include <unistd.h>
import "C"
import "fmt"

func main() {
    foo := 1
    C.close(2)
    fmt.Println(foo)
}

Run this command: gorename -offset demo.go:#78 -to bar

4. What did you expect to see?

It rename without error: Renamed 2 occurrences in 1 file in 1 package.

5. What did you see instead?

I got this error: gorename: -offset "demo.go:#78": no identifier at this position

Tools

Most helpful comment

Having the same issue, is there any workaround on this?

All 3 comments

/cc @alandonovan

Having the same issue, is there any workaround on this?

I'm not sure when (I'm on go 1.9.2) but the error changed to: "gorename: cannot rename identifiers in generated file containing DO NOT EDIT marker"

And took me a while to figure out that gorename doesn't work on cgo files. Should at least change the error message if there isn't going to be a fix anytime soon.

Was this page helpful?
0 / 5 - 0 ratings