Skip to content

Commit 8b626e6

Browse files
aykevldeadprogram
authored andcommitted
compiler: add support for Go 1.23 range-over-func
1 parent 1d1f4fc commit 8b626e6

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

compiler/compiler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,7 @@ func (b *builder) getValue(expr ssa.Value, pos token.Pos) llvm.Value {
19631963
return value
19641964
} else {
19651965
// indicates a compiler bug
1966-
panic("local has not been parsed: " + expr.String())
1966+
panic("SSA value not previously found in function: " + expr.String())
19671967
}
19681968
}
19691969
}

compiler/symbol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
218218
// should be created right away.
219219
// The exception is the package initializer, which does appear in the
220220
// *ssa.Package members and so shouldn't be created here.
221-
if fn.Synthetic != "" && fn.Synthetic != "package initializer" && fn.Synthetic != "generic function" {
221+
if fn.Synthetic != "" && fn.Synthetic != "package initializer" && fn.Synthetic != "generic function" && fn.Synthetic != "range-over-func yield" {
222222
irbuilder := c.ctx.NewBuilder()
223223
b := newBuilder(c, irbuilder, fn)
224224
b.createFunction()

main_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ func TestBuild(t *testing.T) {
9797
if minor >= 22 {
9898
tests = append(tests, "go1.22/")
9999
}
100+
if minor >= 23 {
101+
tests = append(tests, "go1.23/")
102+
}
100103

101104
if *testTarget != "" {
102105
// This makes it possible to run one specific test (instead of all),

testdata/go1.23/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/tinygo-org/tinygo/testdata/go1.23
2+
3+
go 1.23

testdata/go1.23/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
func main() {
4+
testFuncRange(counter)
5+
}
6+
7+
func testFuncRange(f func(yield func(int) bool)) {
8+
for i := range f {
9+
println(i)
10+
}
11+
println("go1.23 has lift-off!")
12+
}
13+
14+
func counter(yield func(int) bool) {
15+
for i := 10; i >= 1; i-- {
16+
yield(i)
17+
}
18+
}

testdata/go1.23/out.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
10
2+
9
3+
8
4+
7
5+
6
6+
5
7+
4
8+
3
9+
2
10+
1
11+
go1.23 has lift-off!

0 commit comments

Comments
 (0)