Skip to content

cmd/compile: ICE when unpacking arguments of variadic generic function #51925

Closed
@sonlamho

Description

@sonlamho

What version of Go are you using (go version)?

$ go version
go version go1.18 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/holamson/.cache/go-build"
GOENV="/home/holamson/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/holamson/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/holamson/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/holamson/.local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/holamson/.local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1142584741=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Link on go.dev/play: https://go.dev/play/p/VgkIIishLsB

Complete runnable program:

package main

import "fmt"

type IntLike interface {
	~int | ~int64 | ~int32 | ~int16 | ~int8
}

func Reduce[T any, U any, Uslice ~[]U](function func(T, U) T, sequence Uslice, initial T) T {
	result := initial
	for _, x := range sequence {
		result = function(result, x)
	}
	return result
}

func min[T IntLike](x, y T) T {
	if x < y {
		return x
	}
	return y

}

// Min returns the minimum element of `nums`.
func Min[T IntLike, NumSlice ~[]T](nums NumSlice) T {
	if len(nums) == 0 {
		return T(0)
	}
	return Reduce(min[T], nums, nums[0])
}

// VarMin is the variadic version of Min.
func VarMin[T IntLike](nums ...T) T {
	return Min(nums)
}

type myInt int

func main() {
	fmt.Println(VarMin(myInt(1), myInt(2))) // OK

	seq := []myInt{1, 2}
	fmt.Println(Min(seq))       // OK
	fmt.Println(VarMin(seq...)) // ERROR

}

What did you expect to see?

Expected output:

1
1
1

What did you see instead?

./prog.go:46:20: internal compiler error: assigning nums (type []myInt) to parameter nums (type go.shape.[]int_1)

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

Go build failed.

Activity

changed the title [-]affected/package: go1.18[/-] [+]affected/package: go1.18 compiler error in unpacking arguments of variadic function[/+] on Mar 24, 2022
changed the title [-]affected/package: go1.18 compiler error in unpacking arguments of variadic function[/-] [+]affected/package: go1.18 compiler error when unpacking arguments of variadic function[/+] on Mar 24, 2022
changed the title [-]affected/package: go1.18 compiler error when unpacking arguments of variadic function[/-] [+]affected/package: go1.18 compiler error when unpacking arguments of variadic generic function[/+] on Mar 24, 2022
changed the title [-]affected/package: go1.18 compiler error when unpacking arguments of variadic generic function[/-] [+]cmd/compile: go1.18 compiler error when unpacking arguments of variadic generic function[/+] on Mar 24, 2022
changed the title [-]cmd/compile: go1.18 compiler error when unpacking arguments of variadic generic function[/-] [+]cmd/compile: ICE when unpacking arguments of variadic generic function[/+] on Mar 24, 2022
added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Mar 24, 2022
added this to the Backlog milestone on Mar 24, 2022
mknyszek

mknyszek commented on Mar 24, 2022

@mknyszek
Contributor
mknyszek

mknyszek commented on Mar 24, 2022

@mknyszek
Contributor
ianlancetaylor

ianlancetaylor commented on Mar 24, 2022

@ianlancetaylor
Contributor
modified the milestones: Backlog, Go1.19 on Mar 24, 2022
findleyr

findleyr commented on Mar 25, 2022

@findleyr
Member

The error message here looks similar to #51909, though I have not confirmed that this is a dupe.

mdempsky

mdempsky commented on Mar 25, 2022

@mdempsky
Contributor

Prints the expected output with GOEXPERIMENT=unified.

gopherbot

gopherbot commented on Mar 25, 2022

@gopherbot
Contributor

Change https://go.dev/cl/395854 mentions this issue: cmd/compile: don't inline fn with shape params, but passed no shape arg

heschi

heschi commented on May 11, 2022

@heschi
Contributor

ping: this is a release blocker that hasn't been updated in a while.

added
NeedsFixThe path to resolution is known, but the work has not been done.
and removed
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on May 14, 2022
locked and limited conversation to collaborators on May 14, 2023
added a commit that references this issue on Sep 19, 2024
cb458c0
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

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.genericsIssue is related to genericsrelease-blocker

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mdempsky@mknyszek@dmitshur@ianlancetaylor@gopherbot

        Issue actions

          cmd/compile: ICE when unpacking arguments of variadic generic function · Issue #51925 · golang/go