The following program result in SIGSEGV on linux,
package main
import (
"fmt"
)
type A struct {
K int
S string
M map[string]string
}
func newA(k int, s string) (a A) {
a.K = k
a.S = s
a.M = make(map[string]string)
a.M[s] = s
return
}
func proxy() (x int, a A) {
return 1, newA(2, "3")
}
func consume(x int, a interface{}) {
fmt.Println(x)
fmt.Println(a)
}
func main() {
consume(proxy())
}
== Using Go tip
20:00 master ms 1 % go version
go version devel +265303525c Thu Oct 25 19:51:46 2018 +0700 linux/amd64
20:04 ~/tmp/sandbox/go/src/bug/fparamf
master ms 0 % go run ./main.go
1
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x12 pc=0x482365]
goroutine 1 [running]:
fmt.(*pp).printArg(0xc00009e000, 0x2, 0x4b6292, 0x76)
/home/ms/Programs/go/src/fmt/print.go:648 +0x185
fmt.(*pp).doPrintln(0xc00009e000, 0xc00009af38, 0x1, 0x1)
/home/ms/Programs/go/src/fmt/print.go:1157 +0xb1
fmt.Fprintln(0x4cb1a0, 0xc00000e018, 0xc00009af38, 0x1, 0x1, 0x2, 0x0,
0x0) /home/ms/Programs/go/src/fmt/print.go:265 +0x58
fmt.Println(0xc00009af38, 0x1, 0x1, 0x2, 0x0, 0x0)
/home/ms/Programs/go/src/fmt/print.go:275 +0x57
main.consume(0x1, 0x2, 0x4b6292)
/home/ms/tmp/sandbox/go/src/bug/fparamf/main.go:27 +0xb3
main.main()
/home/ms/tmp/sandbox/go/src/bug/fparamf/main.go:31 +0xa7
exit status 2
== Using Go 1.11.1
20:04 ~/tmp/sandbox/go/src/bug/fparamf
master ms 1 % go version
go version go1.11.1 linux/amd64
20:06 ~/tmp/sandbox/go/src/bug/fparamf
master ms 0 % go run ./main.go
1
{2 3 map[3:3]}
Is there on going progress on compiler? I am hesitant to report this as
an issue on Github.
--
{ "github":"
github.com/shuLhan", "site":"
kilabit.info" }