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

Fetching a oneof doesn't return the default value (when not set) #22

Closed
thomasvl opened this issue Sep 30, 2016 · 5 comments
Closed

Fetching a oneof doesn't return the default value (when not set) #22

thomasvl opened this issue Sep 30, 2016 · 5 comments

Comments

@thomasvl
Copy link
Collaborator

The fields in a oneof are just fields. So fetching it should still return the default value even when the oneof was set to a different element.

This also allows proto authors to modify a proto by moving a field into a oneof in the future. From a wire format pov, nothing changes.

@tbkka
Copy link
Contributor

tbkka commented Sep 30, 2016

I think your comment only applies to proto3?

In proto2, oneof fields are optionals, and we map proto2 optionals to Swift optionals, so the default value in that case is nil.

Oh. I suppose proto2 optionals can have explicit default values? I don't think I've seen that case, but that would make sense as well.

@thomasvl
Copy link
Collaborator Author

You can also have a message in the oneof, so returning the default there to dot into the default fields also is useful.

@tbkka
Copy link
Contributor

tbkka commented Sep 30, 2016

You can also have a message in the oneof, so returning the default there to dot into the default fields also is useful.

Yes, good point. Are there examples of this in the google/protobuf/unittest_* protos? If so, then it should be easy to fill in some tests for these cases.

@thomasvl
Copy link
Collaborator Author

@thomasvl
Copy link
Collaborator Author

PR #119 added tests to confirm this got fixed in PR #102

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

No branches or pull requests

2 participants