Skip to content

cmd/compile: comparable does not match each comparable type #51392

Closed
@blaubaer

Description

@blaubaer

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

$ go version
go version devel go1.18-a064a4f29a Sat Feb 26 01:16:03 2022 +0000 windows/amd64

Does this issue reproduce with the latest release?

With the latest revision on master (a064a4f29a97a4fc7398d1ac9d7c53c5ba0bc646).

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

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\protected\AppData\Local\go-build
set GOENV=C:\Users\protected\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\protected\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\protected\go
set GOPRIVATE=
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fmessage-length=0 -fdebug-prefix-map=C:\Users\protected\AppData\Local\Temp\go-build4145725796=/tmp/go-build -gno-record-gcc-switches

What did you do?

language.Tag as Map key

package main

import (
	"fmt"

	"golang.org/x/text/language"
)

func main() {
	aMap := map[language.Tag]string{
		language.German: "foo",
	}
	fmt.Println(aMap)
}

language.Tag as comparable generic parameter

package main

import (
	"fmt"
	"golang.org/x/text/language"
)

func doSomething[K comparable](with map[K]string) {
	fmt.Println("comparable", with)
}

func main() {
	aMap := map[language.Tag]string{
		language.German: "foo",
	}
	doSomething(aMap)
}

The following code

What did you expect to see?

  1. language.Tag as Map key: Is accepted by the compiler.
  2. language.Tag as comparable generic parameter: Is accepted by the compiler.

What did you see instead?

  1. language.Tag as Map key: Is accepted by the compiler.
  2. language.Tag as comparable generic parameter: Compiler refuses compiling with
    foo_broken.go:16:13: "golang.org/x/text/language".Tag does not implement comparable
    

ℹ️ I'm pretty sure that this was working at least ~1 week ago with the master. With revision a289e9ce7514a34cd930469322395bf0e89b59ea) it was working.

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.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions