You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, in the Dart protobuf implementation, all fields are nullable in the constructor of message classes, even if they are not optional. This makes it hard to know before runtime if a required field has been assigned, which can lead to runtime errors and harder-to-debug code.
I propose adding a feature that enforces nullability checks in the constructor of message classes based on whether the fields are optional or required. This would make it easier for developers to ensure that all required fields have been assigned before runtime.
This would allow developers to ensure that required fields have been assigned before creating an instance of the message class, preventing runtime errors and making the code more robust.
The text was updated successfully, but these errors were encountered:
duck-dev-go
changed the title
Enforce nullability for optional fields in message constructors
FEATURE: Enforce nullability for optional fields in message constructors
Apr 17, 2023
duck-dev-go
changed the title
FEATURE: Enforce nullability for optional fields in message constructors
FEATURE: Only optional fields nullable in generate message constructor
Apr 17, 2023
Description:
Currently, in the Dart protobuf implementation, all fields are nullable in the constructor of message classes, even if they are not optional. This makes it hard to know before runtime if a required field has been assigned, which can lead to runtime errors and harder-to-debug code.
I propose adding a feature that enforces nullability checks in the constructor of message classes based on whether the fields are optional or required. This would make it easier for developers to ensure that all required fields have been assigned before runtime.
Example:
Consider the following .proto file:
The generated Dart code should have a constructor that enforces null checks for required fields, like so:
This would allow developers to ensure that required fields have been assigned before creating an instance of the message class, preventing runtime errors and making the code more robust.
The text was updated successfully, but these errors were encountered: