Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: internal compiler error: order.stmt CALLMETH when use closure #57440

Closed
nejisama opened this issue Dec 22, 2022 · 1 comment
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge

Comments

@nejisama
Copy link

nejisama commented Dec 22, 2022

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)?

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/neji.bp/.cache/go-build"
GOENV="/home/neji.bp/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/neji.bp/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/neji.bp/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2499534747=/tmp/go-build -gno-record-gcc-switches"

What did you do?

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:

  1. use closure
  2. use an interface , like the type Header interface in my code
  3. 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

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 22, 2022
@cuonglm
Copy link
Member

cuonglm commented Dec 22, 2022

Duplicated of #57309

@cuonglm cuonglm closed this as completed Dec 22, 2022
@golang golang locked and limited conversation to collaborators Dec 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

3 participants