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

"no declaration found" when a package uses a binary literal #121

Open
krisreeves-stripe opened this issue May 5, 2020 · 0 comments
Open

Comments

@krisreeves-stripe
Copy link

This threw me for a loop because it was causing VS Code to fail to show context info on lots of stuff from a child package in a project I'm working on. I eventually narrowed it down to the following:

main.go

package main

import (
	"fmt"
	"godefbug/fails"
	"godefbug/works"
)

// Ping pongs
func Ping() string {
	bang := []byte{0b00100001}
	return fmt.Sprintf("Pong%s", bang)
}

func main() {
	fmt.Println(works.Ping())
	fmt.Println(fails.Ping())
	fmt.Println(Ping())
}

fails/fails.go

package fails

import "fmt"

// Ping pongs
func Ping() string {
	bang := []byte{0b00100001}
	return fmt.Sprintf("Pong%s", bang)
}

works/works.go

package works

import "fmt"

// Ping pongs
func Ping() string {
	bang := []byte{0x21}
	return fmt.Sprintf("Pong%s", bang)
}

output:

$ ~/go/bin/godef -t -f ./main.go -o 204
/Users/krisreeves/go/src/godefbug/works/works.go:6:6
Ping func() string
$ ~/go/bin/godef -t -f ./main.go -o 231
godef: no declaration found for &{fails Ping}
$ ~/go/bin/godef -t -f ./main.go -o 252
./main.go:10:6
Ping func() string
$ go run main.go
Pong!
Pong!
Pong!

It doesn't have to be looking at a function that is directly involved, either:

main.go

package main

import (
	"fmt"
	"godefbug/fails"
	"godefbug/works"
)

// Ping pongs
func Ping() string {
	bang := []byte{0b00100001}
	return fmt.Sprintf("Pong%s", bang)
}

func main() {
	fmt.Println(works.Ping())
	fmt.Println(fails.Ping())
	fmt.Println(Ping())
	fails.NotEvenTheSameFile()
}

fails/whatever.go:

package fails

import "fmt"

// NotEvenTheSameFile fails too
func NotEvenTheSameFile() {
	fmt.Println("???")
}

gives:

$ ~/go/bin/godef -t -f ./main.go -o 267
godef: no declaration found for &{fails NotEvenTheSameFile}
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