Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go build generics backwards compatibility #61850

Closed
pconstantinou opened this issue Aug 8, 2023 · 2 comments
Closed

go build generics backwards compatibility #61850

pconstantinou opened this issue Aug 8, 2023 · 2 comments

Comments

@pconstantinou
Copy link

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

1.21.0

Does this issue reproduce with the latest release?

Yes, it was introduced with 1.21.

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

go env Output
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/phil/.cache/go-build'
GOENV='/home/phil/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/phil/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/phil/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/phil/go/src/github.com/automaticCRM/memdb/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3575205802=/tmp/go-build -gno-record-gcc-switches'

What did you do?

My code that compiled under go 1.20 with generics fails to compile with go 1.21.

Error message:

../../csvctd/ctdcsv.go:324:47: type func(a model.HumanCompanyRole, b model.HumanCompanyRole) bool of func(a, b model.HumanCompanyRole) bool {…} does not match inferred type func(a model.HumanCompanyRole, b model.HumanCompanyRole) int for func(a E, b E) int
       var companyContactRelationships []model.HumanCompanyRole = ....
       slices.SortFunc(companyContactRelationships, func(a, b model.HumanCompanyRole) bool {
                return a.Company.CompanyName < b.Company.CompanyName &&
                        a.CompanyRole.Title < b.CompanyRole.Title &&
                        a.CompanyRole.WhenEnded < b.CompanyRole.WhenEnded &&
                        a.CompanyRole.IsCurrent && a.CompanyRole.IsCurrent != b.CompanyRole.IsCurrent &&
                        a.CompanyRole.WhenStarted < b.CompanyRole.WhenStarted
        })

What did you expect to see?

I expected backward compatibility.

What did you see instead?

Compile errors.

@seankhliao
Copy link
Member

slices was in golang.org/x/exp, there was no stability guarantee for that
you were also not up to date on x/exp for it to break.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2023
@AlekSi
Copy link
Contributor

AlekSi commented Jan 9, 2024

See also: #61374

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants