-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis/passes/loopclosure: disable checker after go1.22.
Uses the (*types.Info).FileVersion to disable the loopclosure checker when in an *ast.File that uses GoVersion >= 1.22. Updates golang/go#62605 Updates golang/go#63888 Change-Id: I2ebe974bc2ee2323eafb0f02d455ab76b3b9268d Reviewed-on: https://go-review.googlesource.com/c/tools/+/539016 Run-TryBot: Tim King <taking@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
- Loading branch information
1 parent
a1ca4fc
commit cd62b43
Showing
7 changed files
with
167 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
go/analysis/passes/loopclosure/testdata/src/versions/go18.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Test loopclosure at go version go1.18. | ||
|
||
-- go.mod -- | ||
module golang.org/fake/versions | ||
|
||
go 1.18 | ||
-- pre.go -- | ||
//go:build go1.18 | ||
|
||
package versions | ||
|
||
func InGo18(l []int) { | ||
for i, v := range l { | ||
go func() { | ||
print(i) // want "loop variable i captured by func literal" | ||
print(v) // want "loop variable v captured by func literal" | ||
}() | ||
} | ||
} | ||
-- go22.go -- | ||
//go:build go1.22 | ||
|
||
package versions | ||
|
||
func InGo22(l []int) { | ||
for i, v := range l { | ||
go func() { | ||
print(i) // Not reported due to file's GoVersion. | ||
print(v) // Not reported due to file's GoVersion. | ||
}() | ||
} | ||
} | ||
-- modver.go -- | ||
package versions | ||
|
||
func At18FromModuleVersion(l []int) { | ||
for i, v := range l { | ||
go func() { | ||
print(i) // want "loop variable i captured by func literal" | ||
print(v) // want "loop variable v captured by func literal" | ||
}() | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
go/analysis/passes/loopclosure/testdata/src/versions/go22.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Test loopclosure at go version go1.22. | ||
-- go.mod -- | ||
module golang.org/fake/versions | ||
|
||
go 1.22 | ||
-- pre.go -- | ||
//go:build go1.19 | ||
|
||
package versions | ||
|
||
func Bad(l []int) { | ||
for i, v := range l { | ||
go func() { | ||
print(i) // want "loop variable i captured by func literal" | ||
print(v) // want "loop variable v captured by func literal" | ||
}() | ||
} | ||
} | ||
-- go22.go -- | ||
//go:build go1.22 | ||
|
||
package versions | ||
|
||
func InGo22(l []int) { | ||
for i, v := range l { | ||
go func() { | ||
print(i) // Not reported due to file's GoVersion. | ||
print(v) // Not reported due to file's GoVersion. | ||
}() | ||
} | ||
} | ||
|
||
-- modver.go -- | ||
package versions | ||
|
||
func At22FromTheModuleVersion(l []int) { | ||
for i, v := range l { | ||
go func() { | ||
print(i) // Not reported due to module's GoVersion. | ||
print(v) // Not reported due to module's GoVersion. | ||
}() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.