protoc-gen: Refactor optional field generation (KRPC-262)#644
Open
protoc-gen: Refactor optional field generation (KRPC-262)#644
Conversation
Contributor
Author
|
Not yet implemented:
|
…function generation
… for optional fields (KRPC-262)
…ate generation settings
909b5cd to
9ebd906
Compare
…tation, remove outdated logic
Jozott00
commented
Apr 4, 2026
Comment on lines
+53
to
+57
| internal object FirGeneratedProtoMessageBuilderFunctionKey : GeneratedDeclarationKey() { | ||
| override fun toString(): String { | ||
| return "FirGeneratedProtoMessageBuilderFunctionKey" | ||
| } | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Not sure if this is actually needed, or if we could just use the PropertyKey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Subsystem
Protobuf/protoc-gen
Problem Description
Currently, optional fields that lack a user-defined default value are generated as nullable properties, with the exception of sub-message fields.
This implementation differs from the standard protobuf approach, which handles all optional fields as non-nullable. This allows users to quickly access default values for non-set subfields. Furthermore, in the edition 2023+ version, where all fields are typically optional by default, managing nullable properties becomes cumbersome.
Solution
This PR aligns the implementation with official Protobuf implementations, ensuring that all fields (except one-of fields that lack a default value) are non-nullable. However, to maintain Kotlin’s idiomatic nullable handling, users can enable additional nullable getter generation, which produces
Additionally,
MyMessage.Builder.clear<Field>()functions are generated for all fields that are presence tracked. This enables users to clear the original set value in the copy block