Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/steep/interface/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,16 @@ def shape(type, public_only:, config:)
if expanded = factory.deep_expand_alias(type)
shape(expanded, public_only: public_only, config: config)&.update(type: type)
end
when AST::Types::Any, AST::Types::Bot, AST::Types::Void, AST::Types::Top
when AST::Types::Top
if definition_builder.env.interface_decls.key?(TypeName('::_Top'))
# rbs-3.3 or newer
type_ = AST::Types::Name::Interface.new(name: TypeName('::_Top'), args: [])
else
type_ = AST::Types::Name::Instance.new(name: TypeName('::BasicObject'), args: [])
end

shape(type_, public_only: public_only, config: config)&.update(type: type)
when AST::Types::Any, AST::Types::Bot, AST::Types::Void
nil
when AST::Types::Var
if bound = config.variable_bounds[type.name]
Expand Down
41 changes: 41 additions & 0 deletions test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6596,6 +6596,47 @@ def test_send_top_void
end
end

def test_send_boolish1
with_checker(<<RBS) do |checker|
type boolish = top

interface _Top
def !: () -> bool
end
RBS
source = parse_ruby(<<-RUBY)
# @type var a: boolish
a = _ = nil
puts 'Hello' if !a
RUBY

with_standard_construction(checker, source) do |construction, typing|
_, constr = construction.synthesize(source.node)

assert_equal 0, typing.errors.size
end
end
end

def test_send_boolish2
# for old RBS package (no _Top interface definition)
with_checker(<<RBS) do |checker|
type boolish = top
RBS
source = parse_ruby(<<-RUBY)
# @type var a: boolish
a = _ = nil
puts 'Hello' if !a
RUBY

with_standard_construction(checker, source) do |construction, typing|
_, constr = construction.synthesize(source.node)

assert_equal 0, typing.errors.size
end
end
end

def test_send_concrete_receiver
with_checker(<<RBS) do |checker|
class SendTest
Expand Down