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 · 3 comments

Comments

@virtuald
Copy link

commented Aug 13, 2018

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

This comment has been minimized.

Copy link

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 this to the Unplanned milestone Aug 13, 2018

@andybons

This comment has been minimized.

Copy link
Member

commented Aug 13, 2018

@rsc

This comment has been minimized.

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.