-
Notifications
You must be signed in to change notification settings - Fork 185
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
Impossible to distinguish the oneof
fields from non-oneof
fields when creating/using a generated class instance.
#875
Comments
If you look at the specification https://protobuf.dev/programming-guides/proto3/#oneof
So really in the interface they look like normal fields. The special semantics is when setting:
So if you pass in multiple values in the constructor only one will end up being set. Don't do that. How would you have expected oneofs to be represented? If Dart had some kind of union-types it could perhaps be modeled nicer in the constructor interface. |
I would imagine something like this to be possible to represent in Dart 3 via sealed classes. Generated classes could look something like this: class FormEntry {
factory FormEntry({
$core.String? name,
FormEntry_Field? field,
})
...
FormEntry_Field? get field => ...;
}
sealed class FormEntry_Field {}
class FormEntry_Field_StaticText extends FormEntry_Field {
factory FormEntry_Field_StaticText({
StaticTextField? staticText,
})
...
StaticTextField get staticText => ...;
}
class FormEntry_Field_TextInput extends FormEntry_Field {
factory FormEntry_Field_TextInput({
TextInputField? textInput,
})
...
TextInputField get textInput => ...;
} |
I was just searching around whether generating sealed classes has been implemented and came across this issue. I think it's a great idea. |
Imagine looking at the following factory constructor (and the available properties) of a generated class:
Can I specify both the
staticText
andtextInput
at the same time? Looks like yes.In reality, though, I can't, since it corresponds to the following protobuf:
Notice how the generated class structure differs from protobuf, making it look like the
staticText
andtextInput
are simple fields that can both exist at the same time.Using only the generated code (without thoroughly looking into its
.proto
source), it seems to be impossible to figure out if certain fields belong to aoneof
group or not.The text was updated successfully, but these errors were encountered: