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

cmd/go: diagnose platform-specific identifiers when building for other platforms #26967

Open
virtuald opened this issue Aug 13, 2018 · 4 comments
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@virtuald
Copy link

What version of Go are you using (go version)?

go version go1.10.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

main.go:

package main

func main() {
	foo()
}

foo_windows.go:

package main

import "fmt"

func foo() {
	fmt.Println("Windows")
}

Execute this command to get the error below:

$ GOOS=darwin go build

What did you expect to see?

./main.go:4:2: undefined for darwin_amd64: foo (defined for windows)

What did you see instead?

./main.go:4:2: undefined: foo

Context

When a colleague that had not used golang previously tried to compile some linux-specific project on OSX, they got the 'undefined' error above and assumed the project was simply broken, not that it was platform-specific. If the golang compiler gave this user a better error message, they most likely would have figured out their issue quicker.

It seems to me that when the compiler runs into an undefined function/constant/whatever, it would be really useful if it could look at the other platform-specific files in that directory and see if they are defined there. If so, it could emit a better error message noting that the function isn't defined for the particular platform that you're compiling for, but that it is defined for other platforms (and mention which ones).

Thinking about my imagined solution, when encountering this type of error the compiler could probably 'quickly' scan the AST of other platforms and see if the thing was defined there? In particular, since this would only be done on error, that wouldn't affect compile performance in general?

Thanks for your consideration.

@FMNSSun
Copy link

FMNSSun commented Aug 13, 2018

Would this scale to build tags as well?

@andybons andybons changed the title go: better error message when undefined thing exists for other platforms cmd/go/build: better error message when undefined thing exists for other platforms Aug 13, 2018
@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 13, 2018
@andybons andybons added this to the Unplanned milestone Aug 13, 2018
@andybons
Copy link
Member

@bcmills @rsc

@rsc
Copy link
Contributor

rsc commented Aug 18, 2018

This is a lot of work for seemingly very little benefit. The compiler would otherwise not even know those other files existed (it does not today). I'm not at all convinced the complexity-to-reward ratio is right for this. It seems like godoc.org would be a good place for that information.

@bcmills bcmills changed the title cmd/go/build: better error message when undefined thing exists for other platforms cmd/go: diagnose platform-specific identifiers when building for other platforms Jan 18, 2019
@rajender
Copy link
Contributor

While building one of our projects on windows I got following error. It would have saved me some time if error message said this is caused due to conditional compilation.

build github.com/google/gopacket/afpacket: cannot load github.com/google/gopacket/afpacket: no Go source files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants