golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.51k stars 17.6k forks source link

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

Closed ashb closed 3 weeks ago

ashb commented 8 years ago

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

rakyll commented 8 years ago

/cc @alandonovan

zer09 commented 7 years ago

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

AlexRouSg commented 6 years ago

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.

seankhliao commented 3 weeks ago

closing as obsoleted by #69360