lib/tapioca/dsl/compilers/active_model_attributes.rb in tapioca-0.11.14 vs lib/tapioca/dsl/compilers/active_model_attributes.rb in tapioca-0.11.15

- old
+ new

@@ -70,13 +70,13 @@ sig { returns(T::Array[[::String, ::String]]) } def attribute_methods_for_constant patterns = if constant.respond_to?(:attribute_method_patterns) # https://github.com/rails/rails/pull/44367 - T.unsafe(constant).attribute_method_patterns + constant.attribute_method_patterns else - constant.attribute_method_matchers + T.unsafe(constant).attribute_method_matchers end patterns.flat_map do |pattern| constant.attribute_types.filter_map do |name, value| next unless handle_method_pattern?(pattern) @@ -99,12 +99,17 @@ end HANDLED_METHOD_TARGETS.include?(target.to_s) end - sig { params(attribute_type_value: ::ActiveModel::Type::Value).returns(::String) } + sig { params(attribute_type_value: T.untyped).returns(::String) } def type_for(attribute_type_value) + # This guarantees that the type will remain as T.untyped for attributes in the following form: + # attribute :name + # This is because for a generic attribute with no specified type, ActiveModel::Type::Value.new is returned + return "T.untyped" if attribute_type_value.instance_of?(ActiveModel::Type::Value) + type = case attribute_type_value when ActiveModel::Type::Boolean "T::Boolean" when ActiveModel::Type::Date "::Date" @@ -117,11 +122,10 @@ when ActiveModel::Type::Integer "::Integer" when ActiveModel::Type::String "::String" else - # we don't want untyped to be wrapped by T.nilable, so just return early - return "T.untyped" + attribute_type_value.class.name.to_s end as_nilable_type(type) end