google / google/protobuf.dart

Impossible to distinguish the `oneof` fields from non-`oneof` fields when creating/using a generated class instance.

Open
#875 5 comments 9 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
572
Forks
196
Avg merge
1h 59m
Merged PRs (30d)
2

Description

Imagine looking at the following factory constructor (and the available properties) of a generated class:

```dart
factory FormEntry({
$core.String? name,
StaticTextField? staticText,
TextInputField? textInput,
})
...
StaticTextField get staticText => $_getN(1);
TextInputField get textInput => $_getN(2);
```

Can I specify both the `staticText` and `textInput` at the same time? Looks like yes.

In reality, though, I can't, since it corresponds to the following protobuf:
```proto
message FormEntry {
string name = 1;
oneof field {
StaticTextField static_text = 100;
TextInputField text_input = 101;
}
}
```

Notice how the generated class structure differs from protobuf, making it look like the `staticText` and `textInput` 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 a `oneof` group or not.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.