-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Fix conversion-gen handling of unexported fields and custom conversions of pointers #133325
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
base: master
Are you sure you want to change the base?
Fix conversion-gen handling of unexported fields and custom conversions of pointers #133325
Conversation
… slices of pointers
276db88
to
66f7e30
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liggitt The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -130,6 +140,28 @@ func Convert_example_Conversion_To_v1_Conversion(in *example.Conversion, out *Co | |||
return autoConvert_example_Conversion_To_v1_Conversion(in, out, s) | |||
} | |||
|
|||
func autoConvert_v1_ConversionPrivate_To_example_ConversionPrivate(in *ConversionPrivate, out *example.ConversionPrivate, s conversion.Scope) error { | |||
out.PublicField = in.PublicField | |||
out.privateField = in.privateField |
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.
This is invalid and will fail to compile. The following commit fixes the generator to not produce this line.
@@ -142,26 +142,16 @@ func Convert_example_Conversion_To_v1_Conversion(in *example.Conversion, out *Co | |||
|
|||
func autoConvert_v1_ConversionPrivate_To_example_ConversionPrivate(in *ConversionPrivate, out *example.ConversionPrivate, s conversion.Scope) error { | |||
out.PublicField = in.PublicField | |||
out.privateField = in.privateField | |||
// WARNING: out.privateField is not exported and cannot be set |
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.
This demonstrates the fixed generated conversion.
// FIXME: Provide conversion function to convert *ConversionCustom to *example.ConversionCustom | ||
compileErrorOnMissingConversion() |
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.
These demonstrate the inability of the generated conversion to find the existing custom conversion function it should call here. The following commit fixes this.
/triage accepted |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Allows conversion-gen to successfully generate conversions for protoc-generated types with unexpected state fields.
Prereq of #133026, see discussion thread in #133026 (comment)
Which issue(s) this PR is related to:
#96564
Does this PR introduce a user-facing change?
/sig api-machinery
/cc @saschagrunert