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

When an interface has unexported methods, adding a method is minor, not major #29

Merged
merged 3 commits into from
Sep 13, 2024

Conversation

bobg
Copy link
Owner

@bobg bobg commented Sep 13, 2024

When you add a new method to a type, that's a minor-version change: safe for existing callers to use, but providing new behavior for new code that wants to use it.

But when you add a new method M to an interface, it's a major-version change. Why? Because a caller may have defined its own type T implementing the interface, and if they upgrade, T no longer does unless and until it implements M.

However! Some interfaces are not meant to be implemented outside of the modules in which they're defined. Case in point: EnumDescriptor. It prevents callers from implementing that interface by including an unexported method.

Adding a method to such an interface cannot break calling code, and so is not a major-version change.

This PR demotes a method-added-to-an-interface change from Major to Minor in the specific case where the interface in question contains unexported methods and/or is defined in terms of "internal" types that callers cannot access.

Fixes #28.

…nterface that includes any unexported methods.
Copy link

github-actions bot commented Sep 13, 2024

Modver result

This report was generated by Modver,
a Go package and command that helps you obey semantic versioning rules in your Go module.

This PR does not require a change in your module’s version number.
(You might still consider bumping the patchlevel anyway.)

@bobg bobg marked this pull request as ready for review September 13, 2024 04:36
@bobg bobg merged commit 1c25916 into master Sep 13, 2024
@bobg bobg deleted the bobg/issue28 branch September 13, 2024 04:37
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.

Sometimes, adding to an interface isn't a breaking change
1 participant