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

proposal: cmd/vet: warn about malformed build constraints #43832

Closed
peter-crist opened this issue Jan 21, 2021 · 3 comments
Closed

proposal: cmd/vet: warn about malformed build constraints #43832

peter-crist opened this issue Jan 21, 2021 · 3 comments

Comments

@peter-crist
Copy link

@peter-crist peter-crist commented Jan 21, 2021

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

$ go version 1.15

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
amd64
darwin

What did you do?

As an example, a build tag like // +build unit, !integration, !component will produce unexpected results when running tests. Running go vet does not warn about this type of ill-formed build constraint.

Example

Given the enclosed files:
unit_test.go
// +build unit, !component, !integration

package test

import "fmt"

func init() {
	fmt.Println("unit test")
}
component_test.go
// +build component, !unit, !integration

package test

import "fmt"

func init() {
	fmt.Println("component test")
}
integration_test.go
// +build integration, !unit, !component

package test

import "fmt"

func init() {
	fmt.Println("integration")
}

Running go test ./... -tags unit -v produces:

component test
integration
unit test

While running go test ./... -tags component -v produces:

component test
unit test

And running go test ./... -tags integration -v produces:

integration test

What did you expect to see?

While this conditional syntax is incorrect, the produced output is confusing and running go vet should warn about combining AND immediately followed by OR (i.e. , ). Updating build tags to // +build unit,!integration,!component leads to expected behavior but it would be helpful for go vet to catch and warn about using commas followed by a space in build tags.

What did you see instead?

Running go vet doesn't indicate any issues.

@gopherbot gopherbot added this to the Proposal milestone Jan 21, 2021
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 21, 2021

We are in the process of moving from +build constraints to go:build constraints, which is intended to fix problems like this. See #41184. I think that will address this problem.

@seankhliao seankhliao changed the title proposal: cmd/vet warn unexpected behavior from proposal: cmd/vet warn about malformed build constraints Jan 21, 2021
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals Jan 26, 2021
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 26, 2021

(@peter-crist If that answer is fully satisfactory please feel free to retract this proposal. Otherwise it can go through the usual proposal review process. Thanks.)

@ianlancetaylor ianlancetaylor changed the title proposal: cmd/vet warn about malformed build constraints proposal: cmd/vet: warn about malformed build constraints Jan 26, 2021
@peter-crist peter-crist closed this Feb 6, 2021
@peter-crist
Copy link
Author

@peter-crist peter-crist commented Feb 6, 2021

(@peter-crist If that answer is fully satisfactory please feel free to retract this proposal. Otherwise it can go through the usual proposal review process. Thanks.)

Closing as that should address the issue at hand. Thank you.

@ianlancetaylor ianlancetaylor removed this from Incoming in Proposals Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants