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/refactor/rename: panic when renaming type embedded in another package #12038

Closed
isaiah opened this issue Aug 5, 2015 · 2 comments
Closed

Comments

@isaiah
Copy link

isaiah commented Aug 5, 2015

This is similar to #8924

Following is the regression test:

diff --git a/refactor/rename/rename_test.go b/refactor/rename/rename_test.go
index 1d282a1..dedb399 100644
--- a/refactor/rename/rename_test.go
+++ b/refactor/rename/rename_test.go
@@ -721,6 +721,31 @@ type _ struct{ *foo.U }
                        },
                },

+               {
+                       ctxt: fakeContext(map[string][]string{
+                               "foo": {`package foo; type T int`},
+                               "main": {`package main
+
+import "foo"
+
+type V struct{ *foo.T }
+`},
+                       }),
+                       from: "(main.V).T", to: "U", // the "T" in *foo.T
+                       want: map[string]string{
+                               "/go/src/foo/0.go": `package foo
+
+type U int
+`,
+                               "/go/src/main/0.go": `package main
+
+import "foo"
+
+type V struct{ *foo.U }
+`,
+                       },
+               },
+

Stacktrace:

--- FAIL: TestRewrites-2 (0.01s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x62c78]

goroutine 248 [running]:
testing.func·006()
        /usr/local/Cellar/go/1.4.2/libexec/src/testing/testing.go:441 +0x181
golang.org/x/tools/refactor/rename.(*renamer).checkInPackageBlock(0x2085e0720, 0x2208594da0, 0x2085e8880)
        /Users/isaiah/codes/go/src/golang.org/x/tools/refactor/rename/check.go:104 +0xe78
golang.org/x/tools/refactor/rename.(*renamer).check(0x2085e0720, 0x2208594da0, 0x2085e8880)
        /Users/isaiah/codes/go/src/golang.org/x/tools/refactor/rename/check.go:39 +0x1cc
golang.org/x/tools/refactor/rename.(*renamer).checkStructField(0x2085e0720, 0x208610190)
        /Users/isaiah/codes/go/src/golang.org/x/tools/refactor/rename/check.go:353 +0x871
golang.org/x/tools/refactor/rename.(*renamer).check(0x2085e0720, 0x2208595628, 0x208610190)
        /Users/isaiah/codes/go/src/golang.org/x/tools/refactor/rename/check.go:41 +0x21a
golang.org/x/tools/refactor/rename.Main(0x20867f040, 0x0, 0x0, 0x378830, 0xa, 0x36f1f0, 0x1, 0x0, 0x0)
        /Users/isaiah/codes/go/src/golang.org/x/tools/refactor/rename/rename.go:326 +0x122c
golang.org/x/tools/refactor/rename.TestRewrites(0x2085fa090)
        /Users/isaiah/codes/go/src/golang.org/x/tools/refactor/rename/rename_test.go:1014 +0x21fe
testing.tRunner(0x2085fa090, 0x50b8a8)
        /usr/local/Cellar/go/1.4.2/libexec/src/testing/testing.go:447 +0xbf
created by testing.RunTests
        /usr/local/Cellar/go/1.4.2/libexec/src/testing/testing.go:555 +0xa8b

It works if from is specified as offset, in which case rename can figure out which packages are affected, but if it's specified as main.V.T form, it failed to figure out the original package of the embedded field is also affected.

@josharian josharian changed the title go.tools/refactor/rename: panic when renaming type embedded in another package x/tools/refactor/rename: panic when renaming type embedded in another package Aug 5, 2015
@josharian josharian added this to the Unreleased milestone Aug 5, 2015
@davidrjenni
Copy link
Contributor

I sent a fix.

@gopherbot
Copy link

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

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

5 participants