
Supports showing captured variables for function closures on versions of Go that export informations about the closure struct (Go >= 1.23) Fixes #3612
26 lines
340 B
Go
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()
|
|
}
|