You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use a closure to handle an interface, which writes a map.
The minimum reproduce code like:
package main
type Header interface {
Set(key, value string)
}
type MockHeader struct {
info map[string]string
}
func New() Header {
return &MockHeader{
info: map[string]string{},
}
}
func (h *MockHeader) Set(key, value string) {
h.info[key] = value
}
func main() {
foo := func() Header {
m := New()
m.Set("test", "12345")
return m
}()
_ = foo
}
According to my test, three conditions need to be met will trigger this error:
use closure
use an interface , like the type Header interface in my code
write the map
If the New return a struct pointer directly, it will be ok.
If the write maps like Set is out of closure, it will be ok.
If the function is not a closure but a normal function, it will be ok
What did you expect to see?
build success.
What did you see instead?
go build bug.go
# command-line-arguments
./bug.go:25:22: internal compiler error: order.stmt CALLMETH
Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
The text was updated successfully, but these errors were encountered:
What version of Go are you using (
go version
)?go version go1.19.4 linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
I use a closure to handle an interface, which writes a map.
The minimum reproduce code like:
According to my test, three conditions need to be met will trigger this error:
type Header interface
in my codeIf the
New
return a struct pointer directly, it will be ok.If the write maps like
Set
is out of closure, it will be ok.If the function is not a closure but a normal function, it will be ok
What did you expect to see?
build success.
What did you see instead?
The text was updated successfully, but these errors were encountered: