lib/tapioca/dsl/compilers/protobuf.rb in tapioca-0.7.1 vs lib/tapioca/dsl/compilers/protobuf.rb in tapioca-0.7.2
- old
+ new
@@ -68,12 +68,14 @@
prop :default, String
end
extend T::Sig
- ConstantType = type_member(fixed: Module)
+ ConstantType = type_member { { fixed: Module } }
+ FIELD_RE = /^[a-z_][a-zA-Z0-9_]*$/
+
sig { override.void }
def decorate
root.create_path(constant) do |klass|
if constant == Google::Protobuf::RepeatedField
create_type_members(klass, "Elem")
@@ -86,11 +88,19 @@
parameters = fields.map do |field|
create_kw_opt_param(field.name, type: field.init_type, default: field.default)
end
- klass.create_method("initialize", parameters: parameters, return_type: "void")
+ if fields.all? { |field| FIELD_RE.match?(field.name) }
+ klass.create_method("initialize", parameters: parameters, return_type: "void")
+ else
+ # One of the fields has an incorrect name for a named parameter so creating the default initialize for
+ # it would create a RBI with a syntax error.
+ # The workaround is to create an initialize that takes a **kwargs instead.
+ kwargs_parameter = create_kw_rest_param("fields", type: "T.untyped")
+ klass.create_method("initialize", parameters: [kwargs_parameter], return_type: "void")
+ end
end
end
end
sig { override.returns(T::Enumerable[Module]) }
@@ -105,10 +115,10 @@
sig { params(klass: RBI::Scope, names: String).void }
def create_type_members(klass, *names)
klass.create_extend("T::Generic")
names.each do |name|
- klass.create_type_member(name)
+ klass.create_type_variable(name, type: "type_member")
end
end
sig do
params(