google / google/protobuf.dart

`GeneratedMessage.hasField` documentation can be confusing

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

Description

Maybe I'm being pedantic, but...

```dart
/// Whether this message has a field associated with [tagNumber].
bool hasField(int tagNumber) => _fieldSet._hasField(tagNumber);
```

This can be interpreted as one of these:

- Whether the proto message description has the given field
- Whether the current message object (`this`) has the given field (i.e. "presence")

The difference is important. For example, if I have this message description:

```proto
message MyMsg {
int32 i = 1;
}
```

and I create an empty message, then merge a message with field tag 2, `[msg.hasField(1), msg.hasField(2)]` will be [true, false] in the first interpretation, `[false, true]` in the second.

We should clarify that this method is about the fields set in the current message object.

Contributor guide

Open the contributing guide

Research direction

Locate the GeneratedMessage.hasField declaration and read its current documentation in context. Clarify that the method describes fields set in the current message object, then verify the wording distinguishes message-field presence from the proto message description.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.