Skip to content

Commit

Permalink
build: prep for Go 1.22 by using GOEXPERIMENT=loopvar for tests
Browse files Browse the repository at this point in the history
In this commit, [we prep for some upcoming changes in
Go](https://go.dev/blog/loopvar-preview) by running our tests with
`GOEXPERIMENT=loopvar`. This changes the loop semantics to fix a common
bug where a scoping issue causes a variable to be re-used, which can
cause unintended bugs down the line.

If everything passes with this flag on, then we can keep it on, and also
rest a bit easier knowing that the compiler will fix a class of bugs
that would previously pop up for us.
  • Loading branch information
Roasbeef committed Oct 4, 2023
1 parent 947721f commit 665f4ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ jobs:
- name: git checkout
uses: actions/checkout@v3

- name: Setup go environment
uses: ./.github/actions/setup-go

- name: Run go mod tidy
run: make mod-check

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ COMMIT := $(shell git describe --tags --dirty)

GOBUILD := GO111MODULE=on go build -v
GOINSTALL := GO111MODULE=on go install -v
GOTEST := GO111MODULE=on go test
GOTEST := GOEXPERIMENT=loopvar GO111MODULE=on go test
GOMOD := GO111MODULE=on go mod

GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'
Expand Down

0 comments on commit 665f4ef

Please sign in to comment.