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

Panic when calling receiver methods for non-struct types #48

Open
sanjit-bhat opened this issue Mar 25, 2024 · 0 comments
Open

Panic when calling receiver methods for non-struct types #48

sanjit-bhat opened this issue Mar 25, 2024 · 0 comments

Comments

@sanjit-bhat
Copy link
Collaborator

sanjit-bhat commented Mar 25, 2024

Goose doesn't yet support receiver methods for non-struct types. However, it's probably bad UX to panic (without saying the unsupported error msg), like it does in this example.

type S []byte

func (s S) Receiver() {
	return
}

func bad() {
	var s S
	s.Receiver()
}

After running Goose, I get the following error. Looks like it's assuming the type is a struct and calling the Go NumFields method on it, which panics.

panic: runtime error: invalid memory address or nil pointer dereference
goroutine 15 [running]:
github.com/tchajed/goose.Ctx.declsOrError.func1()
        /Users/sanjit/projects/pdos/goose/interface.go:27 +0x80
panic({0x10246fee0?, 0x10260aee0?})
        /usr/local/go/src/runtime/panic.go:914 +0x218
go/types.(*Struct).NumFields(...)
        /usr/local/go/src/go/types/struct.go:43
github.com/tchajed/goose.structTypeInfo.fields(...)
        /Users/sanjit/projects/pdos/goose/types.go:367
github.com/tchajed/goose.Ctx.selectorMethod({{0x1400017aba0}, 0x14000025e50, 0x1400007e380, {0x14000018db0, 0x26}, {0x1400007e380}, {0x0, 0x0, {0x1023dfa87, 0x4}}, ...}, ...)
        /Users/sanjit/projects/pdos/goose/goose.go:505 +0xeec
...
@sanjit-bhat sanjit-bhat changed the title Panic when writing receiver methods for type re-declarations Panic when calling receiver methods for type re-declarations Mar 25, 2024
@sanjit-bhat sanjit-bhat changed the title Panic when calling receiver methods for type re-declarations Panic when calling receiver methods for non-struct types Mar 25, 2024
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