x/exp/apidiff: incorrect behaviour with user defined type constraints #60911
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
Also reproducible with
master
.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
We run
apidiff
as part of our CI in kubernetes/utils.Recently kubernetes/utils#243 was merged which introduced a type constraint called
ordered
.(
comparable
is what was hoped to be used but since we weren't able to bump to go1.20 back then, we couldn't use it just yet)apidiff
ran successfully in the CI for that PR since it was a new and compatible addition, and hence deemed to be compatible.However, it now fails to run against itself.
Reproducer:
What did you expect to see?
apidiff
runs successfully when run against no new changes.What did you see instead?
Potential Reason
I see that
apidiff
was recently updated to support generics: https://go-review.googlesource.com/c/exp/+/411076However, as part of this change, we check that 2 named types have an identical type parameter list:
https://github.com/golang/exp/blob/2e198f4a06a1643ba6d13f4823bebb46216bcb41/apidiff/correspondence.go#L209-L211
The issue that arises here is that since constraints are considered named types, and we are using
types.Identical
for comparison here, they are defined to be identical if they are part of the same type declaration, and since we now essentially end up with the same type but in two different packages (old
andnew
), and hence are not identical.See here: https://go.dev/play/p/z4AHbUXWA3D
However, on the other hand, if we used something like
comparable
as the type constraint instead of defining our own, things work fine since we no longer end up in the 2 package situation.See here: https://go.dev/play/p/4X2t3TOx-UR
The text was updated successfully, but these errors were encountered: