Closed
Description
package main
import (
"fmt"
"reflect"
)
func f(next func() bool) {
for b := next(); b; b = next() {
fmt.Printf("next() returned %v\n", b)
}
}
func main() {
next := reflect.MakeFunc(reflect.TypeOf((func() bool)(nil)), func(_ []reflect.Value) []reflect.Value {
return []reflect.Value{reflect.ValueOf(false)}
})
reflect.ValueOf(f).Call([]reflect.Value{next})
}
When run, it gives:
unexpected fault address 0x2000060c7a0
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x1 addr=0x2000060c7a0 pc=0x91738]
goroutine 1 [running]:
runtime.throw({0xb67bd?, 0x57074?})
/workdir/go/src/runtime/panic.go:1028 +0x40 fp=0x4000093500 sp=0x40000934d0 pc=0x40c90
runtime.sigpanic()
/workdir/go/src/runtime/signal_unix.go:830 +0x1a0 fp=0x4000093530 sp=0x4000093500 pc=0x55b30
fmt.(*pp).printArg(0x400009e750, {0xa65c0?, 0x2000060c7a0}, 0x76)
/workdir/go/src/fmt/print.go:661 +0x508 fp=0x40000935e0 sp=0x4000093540 pc=0x91738
fmt.(*pp).doPrintf(0x400009e750, {0xb8df1, 0x13}, {0x4000093788?, 0x1, 0x1})
/workdir/go/src/fmt/print.go:1026 +0x210 fp=0x40000936e0 sp=0x40000935e0 pc=0x94180
fmt.Fprintf({0xd7888, 0x40000a6008}, {0xb8df1, 0x13}, {0x4000093788, 0x1, 0x1})
/workdir/go/src/fmt/print.go:204 +0x54 fp=0x4000093740 sp=0x40000936e0 pc=0x8e9c4
fmt.Printf(...)
/workdir/go/src/fmt/print.go:213
main.f(0x4000098240)
/workdir/go/src/test1.go:10 +0x80 fp=0x40000937a0 sp=0x4000093740 pc=0x95020
runtime.call16(0x4000098270, 0xbf0d0, 0x0, 0x0, 0x0, 0x8, 0x4000093ce0)
/workdir/go/src/runtime/asm_arm64.s:461 +0x78 fp=0x40000937c0 sp=0x40000937a0 pc=0x6a6a8
runtime.reflectcall(0xa6880?, 0x4000098240?, 0x1?, 0xb8a94?, 0x0?, 0x12?, 0xa6880?)
<autogenerated>:1 +0x34 fp=0x4000093800 sp=0x40000937c0 pc=0x6e034
reflect.Value.call({0xa6b40?, 0xbf0d0?, 0x1?}, {0xb6663, 0x4}, {0x4000093f50, 0x1, 0x1?})
/workdir/go/src/reflect/value.go:585 +0x61c fp=0x4000093e70 sp=0x4000093800 pc=0x81bec
reflect.Value.Call({0xa6b40?, 0xbf0d0?, 0xbf0d8?}, {0x4000093f50?, 0x0?, 0x0?})
/workdir/go/src/reflect/value.go:368 +0x90 fp=0x4000093ef0 sp=0x4000093e70 pc=0x81520
main.main()
/workdir/go/src/test1.go:18 +0x148 fp=0x4000093f70 sp=0x4000093ef0 pc=0x952f8
runtime.main()
/workdir/go/src/runtime/proc.go:250 +0x254 fp=0x4000093fd0 sp=0x4000093f70 pc=0x43284
runtime.goexit()
/workdir/go/src/runtime/asm_arm64.s:1155 +0x4 fp=0x4000093fd0 sp=0x4000093fd0 pc=0x6c6c4
Works fine on amd64.