-
Notifications
You must be signed in to change notification settings - Fork 211
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
Support AllowUnexportedWithinModule #116
base: master
Are you sure you want to change the base?
Conversation
A problem with PackagePrefix is that it assumes that package paths are universally stable. There are two failure cases I can think of:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test?
979f9b0
to
6c80e02
Compare
LGTM. (Is there no button to press for LGTM? If so, I can't find it. I miss Gerrit.) |
For sufficiently large codebases with many struct types defined, it is untenable to specify a large list of all types in the repository that AllowUnexported permits visibility for. In Go, we observe that code with a shared owner often lives in the same repository, and all sub-packages within a repository often share a common package path prefix. Thus, permit expressing visibility allowances in terms of package path prefixes instead of individual types. While not explicitly documented, this feature allows the universal comparing of unexported fields on all types: cmp.Equal(x, y, cmp.AllowUnexportedWithinModule("")) This "feature" is intentionally undocumented (but a natural side-effect of the expressed behavior of PackagePrefix) since it considered to be bad practice.
Apologies for the flurry of changes; was struggling to find a good name. I settled on (Thumbs up if the name is fine with you) |
Hm. "Module" has a very specific definition, however, revolving around go.mod files. I think we should stay away from it unless we really mean it. "PackagePrefix" is verbose, but seems pretty clear. |
I will be fond of this feature when it lands. :) +1 towards "PackagePrefix" for naming. I saw the word "Module" in the commit message and had a brief frission of shock and confusion (e.g. how and why would a library like this know about and read 'go.mod' files?) until reading the full message and patch. |
For sufficiently large codebases with many struct types defined,
it is untenable to specify a large list of all types in the repository
that AllowUnexported permits visibility for.
In Go, we observe that code with a shared owner often lives in the same
repository, and all sub-packages within a repository often share a common
package path prefix. Thus, permit expressing visibility allowances in terms
of package path prefixes instead of individual types.
While not explicitly documented, this feature allows the universal comparing
of unexported fields on all types:
cmp.Equal(x, y, cmp.AllowUnexportedWithinModule(""))
This "feature" is intentionally undocumented (but a natural side-effect of the
expressed behavior of PackagePrefix) since it considered to be bad practice.