Skip to content

cmd/compile: weird float conversion complex128 -> go.shape.float64 with interfaces #79812

Closed

Description

@lmaltsis

Go version

go version go1.27-devel_af5ca31db8 Mon Jun 1 08:07:50 2026 -0700 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='/research/compilers/gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN='/home/user/go/bin'
GOCACHE='/home/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2556255821=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPACKAGESDRIVER=''
GOPATH='/home/user/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/user/software/go/slot-b/src'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/user/software/go/slot-b/src/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.27-devel_af5ca31db8 Mon Jun 1 08:07:50 2026 -0700'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

package main

import (
	"fmt"
)

type Foo interface {
	~float64
}

func bar[T Foo](x T, y func(a T) T) T {
	return y(0)
}

func f[T Foo](x T) T {
	return T(0 + 0i)
}

func g[T Foo](x T) T {
	return bar(0, f[T])
}

func main() {
	fmt.Println(g(0.0))
}

https://go.dev/play/p/VMrFES_tnqJ?v=gotip

What did you see happen?

$ go build /tmp/bug.go
# command-line-arguments
/tmp/bug.go:20:17: internal compiler error: 'g[float64]': weird float conversion complex128 -> go.shape.float64

/tmp/bug.go:20:17: internal compiler error: 'g[go.shape.float64]': weird float conversion complex128 -> go.shape.float64

goroutine 57 [running]:
runtime/debug.Stack()
        /home/user/software/go/slot-b/src/src/runtime/debug/stack.go:26 +0x5e
cmd/compile/internal/base.FatalfAt({0xa10e820?, 0x29c0?}, {0x29c00b3a9b00, 0x25}, {0x29c00b469c50, 0x3, 0x3})
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/base/print.go:232 +0x18b
cmd/compile/internal/base.Fatalf(...)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/base/print.go:197
cmd/compile/internal/ssagen.(*ssafn).Fatalf(0x6?, {0xa?, 0x0?}, {0x108b4bb, 0x1f}, {0x29c00b447020, 0x2, 0x29c00b447020?})
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:8017 +0x171
cmd/compile/internal/ssagen.(*state).Fatalf(0x20?, {0x108b4bb?, 0x29c00a10e8ca?}, {0x29c00b447020?, 0x29c00a10eea8?, 0x29c00a10e938?})
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:1149 +0x67
cmd/compile/internal/ssagen.(*state).conv(0x29c00b42d540, {0x1a85298, 0x29c00b438580}, 0x29c00b2cc460, 0x29c00a1427e0, 0x29c00a447500)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:2968 +0x15af
cmd/compile/internal/ssagen.(*state).exprCheckPtr(0x29c00b42d540, {0x1a85298, 0x29c00b438580}, 0x1)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:3226 +0x18e9
cmd/compile/internal/ssagen.(*state).expr(...)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:3026
cmd/compile/internal/ssagen.(*state).stmt(0x29c00b42d540, {0x1a86940, 0x29c00b470730})
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:1914 +0x69ac
cmd/compile/internal/ssagen.(*state).stmtList(...)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:1649
cmd/compile/internal/ssagen.(*state).stmt(0x29c00b42d540, {0x1a86490, 0x29c00b465b40})
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:1679 +0x6465
cmd/compile/internal/ssagen.(*state).stmtList(...)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:1649
cmd/compile/internal/ssagen.buildssa(0x29c00a39a8c0, 0x2f, 0x0)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:574 +0x2bb4
cmd/compile/internal/ssagen.Compile(0x29c00a39a8c0, 0x2f, 0x0?)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/pgen.go:304 +0x88
cmd/compile/internal/gc.compileFunctions.func2()
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/gc/compile.go:177 +0x85
created by cmd/compile/internal/gc.compileFunctions in goroutine 1
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/gc/compile.go:163 +0xe6

goroutine 10 [running]:
runtime/debug.Stack()
        /home/user/software/go/slot-b/src/src/runtime/debug/stack.go:26 +0x5e
cmd/compile/internal/base.FatalfAt({0xa0c0820?, 0x29c0?}, {0x29c00a0b2060, 0x25}, {0x29c00a096570, 0x3, 0x3})
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/base/print.go:232 +0x18b
cmd/compile/internal/base.Fatalf(...)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/base/print.go:197
cmd/compile/internal/ssagen.(*ssafn).Fatalf(0x6?, {0xa?, 0x0?}, {0x108b4bb, 0x1f}, {0x29c00a0b40a0, 0x2, 0x29c00a0b40a0?})
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:8017 +0x171
cmd/compile/internal/ssagen.(*state).Fatalf(0x20?, {0x108b4bb?, 0x29c00a0c08ca?}, {0x29c00a0b40a0?, 0x29c00a0c0ea8?, 0x29c00a0c0938?})
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:1149 +0x67
cmd/compile/internal/ssagen.(*state).conv(0x29c00a092140, {0x1a85298, 0x29c00a476e00}, 0x29c00a481180, 0x29c00a1427e0, 0x29c00a447500)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:2968 +0x15af
cmd/compile/internal/ssagen.(*state).exprCheckPtr(0x29c00a092140, {0x1a85298, 0x29c00a476e00}, 0x1)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:3226 +0x18e9
cmd/compile/internal/ssagen.(*state).expr(...)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:3026
cmd/compile/internal/ssagen.(*state).stmt(0x29c00a092140, {0x1a86940, 0x29c00b457d10})
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:1914 +0x69ac
cmd/compile/internal/ssagen.(*state).stmtList(...)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:1649
cmd/compile/internal/ssagen.(*state).stmt(0x29c00a092140, {0x1a86490, 0x29c00b465440})
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:1679 +0x6465
cmd/compile/internal/ssagen.(*state).stmtList(...)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:1649
cmd/compile/internal/ssagen.buildssa(0x29c00a39aa00, 0x0, 0x0)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/ssa.go:574 +0x2bb4
cmd/compile/internal/ssagen.Compile(0x29c00a39aa00, 0x0, 0x29c009f006f8?)
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/ssagen/pgen.go:304 +0x88
cmd/compile/internal/gc.compileFunctions.func2()
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/gc/compile.go:177 +0x85
created by cmd/compile/internal/gc.compileFunctions in goroutine 1
        /home/user/software/go/slot-b/src/src/cmd/compile/internal/gc/compile.go:163 +0xe6

What did you expect to see?

Code prints 0, the same way it does if interfaces were not involved

package main

import (
	"fmt"
)

func bar(x float64, y func(a float64) float64) float64 {
	return y(0)
}

func f(x float64) float64 {
	return float64(0 + 0i)
}

func g(x float64) float64 {
	return bar(0, f)
}

func main() {
	fmt.Println(g(0.0))
}

https://go.dev/play/p/kRVPKFybEcW?v=gotip

Activity

  1. self-assigned this
    on Jun 4, 2026
  2. gopherbot commented on Jun 4, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/786920 mentions this issue: cmd/compile: fix conversion from constant to type parameter

  3. added
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    on Jun 10, 2026
  4. added this to the Go1.27 milestone on Jun 10, 2026
  5. added a commit that references this issue on Jun 10, 2026
    6278b72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FixPendingIssues that have a fix which has not yet been reviewed or submitted.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