lib/steep/interface/builder.rb in steep-1.8.3 vs lib/steep/interface/builder.rb in steep-1.9.0.dev.1
- old
+ new
@@ -280,10 +280,11 @@
overloads = method.defs.map do |type_def|
method_name = method_name_for(type_def, name)
method_type = factory.method_type(type_def.type)
method_type = replace_primitive_method(method_name, type_def, method_type)
method_type = replace_kernel_class(method_name, type_def, method_type) { AST::Builtin::Class.instance_type }
+ method_type = add_implicitly_returns_nil(type_def.annotations, method_type)
Shape::MethodOverload.new(method_type, [type_def])
end
shape.methods[name] = Interface::Shape::Entry.new(method_name: name, private_method: method.private?, overloads: overloads)
end
@@ -313,10 +314,11 @@
method_type = factory.method_type(type_def.type)
method_type = replace_primitive_method(method_name, type_def, method_type)
if type_name.class?
method_type = replace_kernel_class(method_name, type_def, method_type) { AST::Types::Name::Singleton.new(name: type_name) }
end
+ method_type = add_implicitly_returns_nil(type_def.annotations, method_type)
Shape::MethodOverload.new(method_type, [type_def])
end
shape.methods[name] = Interface::Shape::Entry.new(method_name: name, private_method: method.private?, overloads: overloads)
end
@@ -584,11 +586,11 @@
shape
end
def record_shape(record)
all_key_type = AST::Types::Union.build(
- types: record.elements.each_key.map {|value| AST::Types::Literal.new(value: value) }
+ types: record.elements.each_key.map {|value| AST::Types::Literal.new(value: value).back_type }
)
all_value_type = AST::Types::Union.build(types: record.elements.values)
hash_type = AST::Builtin::Hash.instance_type(all_key_type, all_value_type)
hash_shape = yield(hash_type) or raise
@@ -819,9 +821,20 @@
end
end
end
method_type
+ end
+
+ def add_implicitly_returns_nil(annotations, method_type)
+ if annotations.find { _1.string == "implicitly-returns-nil" }
+ return_type = method_type.type.return_type
+ method_type = method_type.with(
+ type: method_type.type.with(return_type: AST::Types::Union.build(types: [return_type, AST::Builtin.nil_type]))
+ )
+ else
+ method_type
+ end
end
end
end
end