delve/_fixtures/closurecontents.go
Alessandro Arzilli bbcea6b9f4
proc: support reading captured variables of closures (#3682)
Supports showing captured variables for function closures on versions
of Go that export informations about the closure struct (Go >= 1.23)

Fixes #3612
2024-04-07 21:36:50 -07:00

26 lines
340 B
Go

package main
import (
"fmt"
"runtime"
)
func makeAcc(scale int) func(x int) int {
a := 0
return func(x int) int {
a += x * scale
return a
}
}
func main() {
acc := makeAcc(3)
runtime.Breakpoint()
fmt.Println(acc(1))
runtime.Breakpoint()
fmt.Println(acc(2))
runtime.Breakpoint()
fmt.Println(acc(6))
runtime.Breakpoint()
}