Skip to content

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

@nejisama

Description

@nejisama

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions