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
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) FrozenDueToAge Proposal
Milestone

Comments

@peter-crist
Copy link

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

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
@timothy-king timothy-king added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Jan 26, 2021
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Jan 26, 2021
@ianlancetaylor
Copy link
Contributor

(@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
Copy link
Author

(@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 (old) Mar 22, 2021
@golang golang locked and limited conversation to collaborators Feb 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) FrozenDueToAge Proposal
Projects
None yet
Development

No branches or pull requests

4 participants