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

Add cmpopts.EquateComparable #340

Merged
merged 1 commit into from
Aug 31, 2023
Merged

Add cmpopts.EquateComparable #340

merged 1 commit into from
Aug 31, 2023

Conversation

dsnet
Copy link
Collaborator

@dsnet dsnet commented Aug 31, 2023

This helper function makes it easier to specify that comparable types are safe to directly compare with the == operator in Go.

The API does not use generics as it follows existing options like cmp.AllowUnexported, cmpopts.IgnoreUnexported, or cmpopts.IgnoreTypes.

While generics provides type safety, the user experience is not as nice. Our current API allows multiple types to be specified:

cmpopts.EquateComparable(netip.Addr{}, netip.Prefix{})

While generics would not allow variadic arguments:

cmpopts.EquateComparable[netip.Addr]()
cmpopts.EquateComparable[netip.Prefix]()

Bump mininimum supported Go to 1.18 for net/netip type. Start testing on Go 1.21.

Fixes #339

This helper function makes it easier to specify that comparable types
are safe to directly compare with the == operator in Go.

The API does not use generics as it follows existing options like
cmp.AllowUnexported, cmpopts.IgnoreUnexported, or cmpopts.IgnoreTypes.

While generics provides type safety, the user experience is not as nice.
Our current API allows multiple types to be specified:
	cmpopts.EquateComparable(netip.Addr{}, netip.Prefix{})
While generics would not allow variadic arguments:
	cmpopts.EquateComparable[netip.Addr]()
	cmpopts.EquateComparable[netip.Prefix]()

Bump mininimum supported Go to 1.18 for net/netip type.
Start testing on Go 1.21.

Fixes #339
@dsnet
Copy link
Collaborator Author

dsnet commented Aug 31, 2023

Upgrading to Go 1.18 is not strictly necessary, if we're not ready to do that yet, I can adjust the tests accordingly.
It's still worthwhile to upgrade as that would unblock some other cleanups.

@dsnet dsnet requested a review from neild August 31, 2023 06:50
@dsnet
Copy link
Collaborator Author

dsnet commented Aug 31, 2023

Hmmm... I can't submit this due to CI thinking it still needs to test on Go1.13 to Go 1.15. I feel like we had this issue before, but I don't remember what the resolution was.

@neild neild merged commit c3ad843 into master Aug 31, 2023
19 checks passed
@dsnet dsnet deleted the equate-comparable branch August 31, 2023 17:33
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

Successfully merging this pull request may close these issues.

Default support for the netip package
2 participants