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

rf: panic in Refactor.Load #10

Open
rogpeppe opened this issue Mar 23, 2021 · 1 comment
Open

rf: panic in Refactor.Load #10

rogpeppe opened this issue Mar 23, 2021 · 1 comment

Comments

@rogpeppe
Copy link

commit 6fb3311

While trying to create minimal example to demonstrate #9, I found the following panic.
Reproduce by running the testscript command:

exec rf 'ex {import "example/c"; Foo -> Bar}'
-- a/a.go --
package a

import (
	"example/b"
	"example/c"
)

var F = b.F

func init() {
	b.F = new(c.Foo)
}
-- a/a_test.go --
package a_test

import (
	"example/b"
	"example/c"
	"testing"
)

func TestFoo(t *testing.T) {
	b.F = new(c.Foo)
}
-- b/b.go --
package b

import "example/c"

var F *c.Foo
-- c/c.go --
package c

type Foo int
-- go.mod --
module example

go 1.17

I see this panic:

panic executing: 
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x64e7ce]

goroutine 1 [running]:
main.run.func1(0xc000179ed0)
	/home/rogpeppe/other/rf/rf.go:76 +0xe7
panic(0x6b28e0, 0x8905e0)
	/home/rogpeppe/go/src/runtime/panic.go:972 +0x1d4
rsc.io/rf/refactor.(*Refactor).Load(0xc00005a480, 0xc000070930, 0xc000014210, 0x2)
	/home/rogpeppe/other/rf/refactor/snap.go:336 +0x19ce
main.run(0xc00005a480, 0x7ffff469abc9, 0x23, 0x0, 0x0)
	/home/rogpeppe/other/rf/rf.go:101 +0x238
main.main()
	/home/rogpeppe/other/rf/rf.go:44 +0x1bb
@rogpeppe
Copy link
Author

rogpeppe commented Mar 25, 2021

I investigated this a bit. It seems that the reason for the panic is that
there is no target set here which seems to be because there is no package in the current (top level) directory (this condition is never triggered.

Thus, adding a file dummy.go containing package dummy in the top level directory is a workaround for the panic.

What should the target be if there's no package in the current directory? I've probably misunderstood what "target" means here, but... does it even make sense to have a single target when the tests in every package have their own type universe?

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

1 participant