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

reflect: Type interface is unimplemented comparable (generics) #51179

Open
Code-Hex opened this issue Feb 14, 2022 · 5 comments
Open

reflect: Type interface is unimplemented comparable (generics) #51179

Code-Hex opened this issue Feb 14, 2022 · 5 comments
Labels
NeedsInvestigation
Milestone

Comments

@Code-Hex
Copy link

@Code-Hex Code-Hex commented Feb 14, 2022

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

$ gotip version
go version devel go1.18-e50f0f372b Fri Feb 11 05:11:58 2022 +0000 darwin/arm64

What did you do?

The document for reflect.Type interface has described is comparable.

Type values are comparable, such as with the == operator, so they can be used as map keys.

However, I tried to compare with a function using generics comparable, and I get a compilation error.

What did you expect to see?

compilable

What did you see instead?

compilation error.

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

@hopehook
Copy link
Contributor

@hopehook hopehook commented Feb 14, 2022

I find it is work fine at the my local go source code, which is failed on the go playground.

  • my local version success: go version devel go1.18-a991d9dc27 Thu Jan 27 05:30:27 2022 +0000 darwin/amd64
  • playground version failed: devel go1.18-5bd734839d Sun Feb 13 02:11:11 2022 +0000

So i compiled a new one, it failed also.

  • latest source code of master branch failed: go version devel go1.18-badbc52d82 Mon Feb 14 05:18:03 2022 +0000 darwin/amd64

@hopehook
Copy link
Contributor

@hopehook hopehook commented Feb 14, 2022

@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented Feb 14, 2022

Also CC @findleyr.

Placing it in 1.18 milestone to at least investigate whether something about this needs to be done for 1.18.

@dmitshur dmitshur added the NeedsInvestigation label Feb 14, 2022
@dmitshur dmitshur added this to the Go1.18 milestone Feb 14, 2022
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 14, 2022

It's true that reflect.Type is not treated as a comparable type, and it's true that that may be problematic in some cases. That said, we aren't going to do anything here for 1.18.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Apr 11, 2022

See discussion at #51338 for a way to fix this.

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

No branches or pull requests

4 participants