lib/tapioca/dsl/compilers/protobuf.rb in tapioca-0.8.3 vs lib/tapioca/dsl/compilers/protobuf.rb in tapioca-0.9.0
- old
+ new
@@ -144,10 +144,15 @@
else
"T.untyped"
end
end
+ sig { params(descriptor: Google::Protobuf::FieldDescriptor).returns(T::Boolean) }
+ def nilable_descriptor?(descriptor)
+ descriptor.label == :optional && descriptor.type == :message
+ end
+
sig { params(descriptor: Google::Protobuf::FieldDescriptor).returns(Field) }
def field_of(descriptor)
if descriptor.label == :repeated
# Here we're going to check if the submsg_name is named according to
# how Google names map entries.
@@ -183,9 +188,10 @@
default: "Google::Protobuf::RepeatedField.new(#{default_args.join(", ")})"
)
end
else
type = type_of(descriptor)
+ type = as_nilable_type(type) if nilable_descriptor?(descriptor)
Field.new(
name: descriptor.name,
type: type,
init_type: type,