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

types2, go/types: embedding comparable ignores other type set constraints #47411

Closed
griesemer opened this issue Jul 26, 2021 · 4 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@griesemer
Copy link
Contributor

package p

func f[P interface{comparable; ~map[string]int}](){
        _ = g[P]
}

func g[_ comparable]() {}

should fail to type check because the type set of P is the intersection of all types that are comparable and all map types with underlying type map[string]int, and since map types are not comparable, the intersection is empty. Thus, there is no type that satisfies the comparable constraint for g.

Example adjusted for go2go playground: this fails as expected, but this succeeds unexpectedly.

@griesemer griesemer added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 26, 2021
@griesemer griesemer added this to the Go1.18 milestone Jul 26, 2021
@griesemer griesemer self-assigned this Jul 26, 2021
@griesemer
Copy link
Contributor Author

cc: @findleyr

@gopherbot
Copy link

Change https://golang.org/cl/337354 mentions this issue: [dev.typeparams] cmd/compile/internal/types2: use comparable bit rather than ==() method

gopherbot pushed a commit that referenced this issue Jul 27, 2021
…er than ==() method

This removes the special "==" methods from comparable interfaces in
favor of a "comparable" flag in TypeSets indicating that the interface
is or embeds comparable. Fixes various related implementation
inaccuracies.

While at it, fix setup of the predeclared error and comparable
interface types by associating their respective type name objects
with them.

For #47411.

Change-Id: I409f880c8c8f2fe345621401267e4aaabd17124d
Reviewed-on: https://go-review.googlesource.com/c/go/+/337354
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@gopherbot
Copy link

Change https://golang.org/cl/339652 mentions this issue: [dev.typeparams] go/types: use comparable bit rather than ==() method

gopherbot pushed a commit that referenced this issue Aug 4, 2021
This is a port of CL 337354 to go/types, adjusted for the error
reporting API and to reposition a couple error messages in
issue47411.go2 (the go/types position is probably better).

A panic is also fixed in lookup.go when method lookup fails and static
== false. I'll send a fix for types2 in a separate CL.

For #47411

Change-Id: Icc48f03c3958695f581f10e8675c1f32434c424b
Reviewed-on: https://go-review.googlesource.com/c/go/+/339652
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@griesemer
Copy link
Contributor Author

This was fixed with the CLs above in the dev.typeparams branch which since has been merged into master.

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants