lib/tapioca/compilers/symbol_table/symbol_generator.rb in tapioca-0.4.7 vs lib/tapioca/compilers/symbol_table/symbol_generator.rb in tapioca-0.4.8

- old
+ new

@@ -207,11 +207,15 @@ constant.props.map do |name, prop| method = "prop" method = "const" if prop.fetch(:immutable, false) type = prop.fetch(:type_object, "T.untyped") - indented("#{method} :#{name}, #{type}") + if prop.key?(:default) + indented("#{method} :#{name}, #{type}, default: T.unsafe(nil)") + else + indented("#{method} :#{name}, #{type}") + end end.join("\n") end sig { params(name: String, constant: Module).returns(T.nilable(String)) } def compile_subconstants(name, constant) @@ -511,11 +515,13 @@ return if struct_method?(constant, method_name) return if method_name.start_with?("__t_props_generated_") parameters = T.let(method.parameters, T::Array[[Symbol, T.nilable(Symbol)]]) - sanitized_parameters = parameters.map do |type, name| + sanitized_parameters = parameters.each_with_index.map do |(type, name), index| + fallback_arg_name = "_arg#{index}" + unless name # For attr_writer methods, Sorbet signatures have the name # of the method (without the trailing = sign) as the name of # the only parameter. So, if the parameter does not have a name # then the replacement name should be the name of the method @@ -531,16 +537,16 @@ ) name = if writer_method_with_sig T.must(method_name[0...-1]).to_sym else - :_ + fallback_arg_name end end # Sanitize param names - name = name.to_s.gsub(/[^a-zA-Z0-9_]/, '_') + name = name.to_s.gsub(/[^a-zA-Z0-9_]/, fallback_arg_name) [type, name] end parameter_list = sanitized_parameters.map do |type, name| @@ -610,9 +616,10 @@ signature_body << ".params(#{params})" unless params.empty? signature_body << ".returns(#{returns})" signature_body = signature_body .gsub(".returns(<VOID>)", ".void") .gsub("<NOT-TYPED>", "T.untyped") + .gsub(".params()", "") .gsub(TYPE_PARAMETER_MATCHER, "T.type_parameter(:\\1)")[1..-1] "sig { #{signature_body} }" end