Skip to content

cmd/compile: global variable assignment implicit type conversion error #68264

Closed

Description

@deelawn

Go version

go1.22.4 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/dylan/Library/Caches/go-build'
GOENV='/Users/dylan/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/dylan/go/pkg/mod'
GONOPROXY='github.com/deelawn'
GONOSUMDB='github.com/deelawn'
GOOS='darwin'
GOPATH='/Users/dylan/go'
GOPRIVATE='github.com/deelawn'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/dylan/deelawn/gnoland/gno2/gno/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/6v/ptrk49k16l32ftg2l8x0q8j40000gn/T/go-build4157790115=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

https://go.dev/play/p/AwgUrKVlv9_Z

package main

import "fmt"

type nat []int

var a, b nat = y()

func y() (nat, []int) {
	return nat{0}, nat{1}
}

func main() {
	fmt.Println(a, b)
}

What did you see happen?

./prog.go:7:5: internal compiler error: unexpected initialization statement: a, b = .autotmp_0, .autotmp_1

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new

What did you expect to see?

Expected output of [0] [1], identical to what is output when doing the same assignment to local variables:

package main

import "fmt"

type nat []int

func y() (nat, []int) {
	return nat{0}, nat{1}
}

func main() {
	var a, b nat = y()
	fmt.Println(a, b)
}

Activity

  1. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Jul 1, 2024
  2. thanm commented on Jul 1, 2024

    @thanm
    Contributor

    Thanks for the report.

    Interestingly, this problem appears to have been around for quite some time; I can reproduce it at tip, then in 1.22 all the way back to 1.16 (works ok in 1.15).

    @golang/compiler

  3. dr2chase commented on Jul 1, 2024

    @dr2chase
    Contributor

    I have a nasty suspicion this is something in expand_calls.

  4. cherrymui commented on Jul 1, 2024

    @cherrymui
    Member

    Actually, this panics in the frontend
    https://go.dev/play/p/AwgUrKVlv9_Z?v=gotip

    ./prog.go:7:5: internal compiler error: unexpected initialization statement: a, b = .autotmp_0, .autotmp_1
    
    goroutine 1 [running]:
    runtime/debug.Stack()
    	/usr/local/go/src/runtime/debug/stack.go:26 +0x5e
    cmd/compile/internal/base.FatalfAt({0x479e91?, 0x0?}, {0xe4cd0e, 0x27}, {0xc00045b728, 0x1, 0x1})
    	/usr/local/go/src/cmd/compile/internal/base/print.go:230 +0x1ea
    cmd/compile/internal/staticinit.(*Schedule).tryStaticInit(0xc00045b880, {0xfa51a0, 0xc000437aa0})
    	/usr/local/go/src/cmd/compile/internal/staticinit/sched.go:106 +0x1f7
    cmd/compile/internal/staticinit.(*Schedule).StaticInit(0xc00045b880, {0xfa51a0, 0xc000437aa0})
    	/usr/local/go/src/cmd/compile/internal/staticinit/sched.go:58 +0x26
    cmd/compile/internal/pkginit.MakeTask()
    	/usr/local/go/src/cmd/compile/internal/pkginit/init.go:99 +0x945
    cmd/compile/internal/gc.Main(0xe66fe8)
    	/usr/local/go/src/cmd/compile/internal/gc/main.go:244 +0xffd
    main.main()
    	/usr/local/go/src/cmd/compile/main.go:57 +0xf9
    
  5. gopherbot commented on Jul 2, 2024

    @gopherbot
    Contributor

    Change https://go.dev/cl/596055 mentions this issue: cmd/compile: fix ICE when compiling global a, b = f()

  6. added this to the Go1.23 milestone on Jul 3, 2024
  7. added a commit that references this issue on Jul 5, 2024
    be15292
  8. locked and limited conversation to collaborators on Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions