Skip to content

go/constant: complex != unknown violates Compare contract #75137

@goto1134

Description

@goto1134

Go version

go version go1.26-devel_a21249436b darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/Andrei.Efanov/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/Andrei.Efanov/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/h0/j2mhh5tx4cdcn_2n79qqbcg40000kt/T/go-build2822157088=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/Andrei.Efanov/Projects/chore/go/src/go.mod'
GOMODCACHE='/Users/Andrei.Efanov/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/Andrei.Efanov/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/Andrei.Efanov/Projects/chore/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/Andrei.Efanov/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/Andrei.Efanov/Projects/chore/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.26-devel_a21249436b Mon Aug 25 02:31:40 2025 -0700'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Run the following code:

package main

import (
	"fmt"
	"go/constant"
	"go/token"
)

func main() {
	x := constant.MakeUnknown()
	y := constant.MakeImag(constant.MakeFloat64(1.2))

	fmt.Println("x != y:", constant.Compare(x, token.NEQ, y))
}

What did you see happen?

The output:

x != y: true

What did you expect to see?

The Compare godoc says:

If one of the operands is [Unknown], the result is false.

The output must be:

x != y: false

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions