-
Notifications
You must be signed in to change notification settings - Fork 115
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
Protobuf generated classes should extend from Google::Protobuf::AbstractMessage
#1911
Conversation
494efb3
to
e8bf434
Compare
@@ -86,6 +88,7 @@ def decorate | |||
elsif constant == Google::Protobuf::Map | |||
create_type_members(klass, "Key", "Value") | |||
else | |||
klass.create_include("Google::Protobuf::MessageExts") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think we should instead make these classes subclass from Google::Protobuf::AbstractMessage
instead, which pulls in this include as well: https://github.com/protocolbuffers/protobuf/blob/5d40c4f43409bbcdf7ab2d24cbb4b1c363cfa7a0/ruby/lib/google/protobuf/message_exts.rb#L29
It is a private constant, but since it will only be inside our generated RBI files, that shouldn't be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, at runtime, that is the correct description of these message classes: https://github.com/protocolbuffers/protobuf/blob/5d40c4f43409bbcdf7ab2d24cbb4b1c363cfa7a0/ruby/lib/google/protobuf/ffi/message.rb#L35
lib/tapioca/rbi_ext/model.rb
Outdated
block: T.nilable(T.proc.params(scope: Scope).void), | ||
).returns(Scope) | ||
end | ||
def create_path(constant, superclass_name = nil, &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change doesn't make a lot of sense. We would allow people to pass a superclass_name
for a module constant and just silently drop it?
Instead you could do something like this:
root.create_path(constant) do |klass|
raise unless klass.is_a?(RBI::Class)
klass.superclass_name = "Google::Protobuf::AbstractMessage"
# ...
This reverts commit 0091023.
Updated with @Morriar's suggestion, but looking into the 1 failing test. |
Google::Protobuf::AbstractMessage
Passing on Core. |
Google::Protobuf::AbstractMessage
Google::Protobuf::AbstractMessage
(merging this commit history was unintentional, I was used to the auto-squash in other repos). |
Motivation
Problem reported in Shopify Core that
to_proto
wasn't being recognized.Implementation
Mix in the necessary module.Inherit from
Google::Protobuf::AbstractMessage
.Tests
Updated.