-
Notifications
You must be signed in to change notification settings - Fork 122
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
Fix DSL generation for Google::Protobuf::Struct
#1497
Conversation
I've tested this change against Shopify's Core monolith and against the repository of the service that originally reported the issue, and in both cases this fixes the problem. Some tests are failing in specific CI pipelines due to CI issues (we're accidentally using the latest version of sorbet in those, which has changes we'll need to handle). |
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.
Don't have enough context but the fact that the generated type is same as before gives confidence.
|
||
it "handles FieldsEntry types just like MapEntry types" do | ||
add_ruby_file("content.rb", <<~RUBY) | ||
require 'google/protobuf/struct_pb' |
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.
Nice find
@@ -159,9 +159,9 @@ GEM | |||
activemodel | |||
globalid (1.1.0) | |||
activesupport (>= 5.0) | |||
google-protobuf (3.22.3-arm64-darwin) | |||
google-protobuf (3.22.3-x86_64-darwin) | |||
google-protobuf (3.22.3-x86_64-linux) |
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.
Did we test that the new implementation generates correct RBIs on the old google-protobuf version?
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.
Yes! 👍
`type_of(descriptor)` is returning `nil` for `Google::Protobuf::Struct` methods in `sorbet/rbi/dsl/google/protobuf/struct.rbi` in version 3.23.0.
Co-authored-by: Aiden Storey <[email protected]>
d8bd055
to
2d18510
Compare
Motivation
protobuf
version 3.23.0 introduced changes that maketapioca dsl
generate broken RBI insorbet/rbi/dsl/google/protobuf/struct.rbi
:This RBI change, in turn, causes typechecking errors:
When debugging, I found that
type_of(descriptor)
is now returningnil
forGoogle::Protobuf::Struct
.Implementation
The initial fix (first commit) was making sure that
type_of(descriptor)
will always return aString
value as described in its signature—"T.untyped"
, ifdescriptor.subtype.msgclass.name.nil?
. That fixes all typechecking errors, but it does that generating a signature that seems wrong:This is not actually valid; running
Google::Protobuf::RepeatedField.new(:message, T.untyped)
orGoogle::Protobuf::RepeatedField.new(:message, nil)
or variants like that all fail.While pairing with @bitwise-aiden, we noticed that if we changed conditions inside
#field_of
to get to the same branch it used to get in the previous version, the RBI forGoogle::Protobuf::Struct
doesn't change post update. It does create some changes in other DSL files, but nothing that seems to create typechecking errors.Tests
I'm not quite sure how to reproduce this in a test. Is a test required for this, though, given how specific the issue is and how this is the only case that could benil
?There's now a test that confirms the expected behaviour.
Extra
The changes that started in protocolbuffers/protobuf#12319 might affect our test setup in the future, as they extract the DSL to a separate package.