mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 06:23:39 +00:00
loader: make sure Go version is plumbed through
This fixes the new loop variable behavior in Go 1.22.
Specifically:
* The compiler (actually, the x/tools/go/ssa package) now correctly
picks up the Go version.
* If a module doesn't specify the Go version, the current Go version
(from the `go` tool and standard library) is used. This fixes
`go run`.
* The tests in testdata/ that use a separate directory are now
actually run in that directory. This makes it possible to use a
go.mod file there.
* There is a test to make sure old Go modules still work with the old
Go behavior, even on a newer Go version.
This commit is contained in:
committed by
Ron Evans
parent
38a80b45d3
commit
57f49af726
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
module github.com/tinygo-org/tinygo/testdata/go1.22
|
||||
|
||||
go 1.22
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
testIntegerRange()
|
||||
testLoopVar()
|
||||
}
|
||||
|
||||
func testIntegerRange() {
|
||||
for i := range 10 {
|
||||
println(10 - i)
|
||||
}
|
||||
println("go1.22 has lift-off!")
|
||||
}
|
||||
|
||||
func testLoopVar() {
|
||||
var f func() int
|
||||
for i := 0; i < 1; i++ {
|
||||
if i == 0 {
|
||||
f = func() int { return i }
|
||||
}
|
||||
}
|
||||
// Variable n is 1 in Go 1.21, or 0 in Go 1.22.
|
||||
n := f()
|
||||
if n == 0 {
|
||||
println("loops behave like Go 1.22")
|
||||
} else if n == 1 {
|
||||
println("loops behave like Go 1.21")
|
||||
} else {
|
||||
println("unknown loop behavior")
|
||||
}
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
10
|
||||
9
|
||||
8
|
||||
7
|
||||
6
|
||||
5
|
||||
4
|
||||
3
|
||||
2
|
||||
1
|
||||
go1.22 has lift-off!
|
||||
loops behave like Go 1.22
|
||||
Reference in New Issue
Block a user