Skip to content

Commit 366c2c6

Browse files
authored
Merge pull request #59 from ruby/intersection_fallback
Handle RBS::Types::Intersection (fallback to union type)
2 parents ec43826 + 47592a4 commit 366c2c6

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/repl_type_completor/types.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ def self.from_rbs_type(return_type, self_type, extra_vars = {})
406406
OBJECT
407407
end
408408
end
409-
when RBS::Types::Union
409+
when RBS::Types::Union, RBS::Types::Intersection
410+
# Intersection is unsupported. fallback to union type
410411
UnionType[*return_type.types.map { from_rbs_type _1, self_type, extra_vars }]
411412
when RBS::Types::Proc
412413
PROC
@@ -455,6 +456,8 @@ def self.from_rbs_type(return_type, self_type, extra_vars = {})
455456
params = names.map.with_index { [_1, args[_2] || OBJECT] }.to_h
456457
end
457458
InstanceType.new klass, params || {}
459+
else
460+
OBJECT
458461
end
459462
end
460463

test/repl_type_completor/test_type_analyze.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,11 @@ def test_rbs_untyped_function
744744
assert_call('proc{}.call; 1.', include: Integer)
745745
end
746746

747+
def test_rbs_intersection_type_fallback
748+
# One of the overloads of Kernel.Rational(a, b) has `Numeric & _RationalDiv[T]`
749+
assert_call('Rational(a,b).', include: Rational)
750+
end
751+
747752
def test_rbs_instance_type
748753
assert_call('Thread.start{}.', include: Thread)
749754
assert_call('"".encode("utf-8").', include: String)

0 commit comments

Comments
 (0)