Skip to content

Commit

Permalink
Merge pull request #647 from kachick/fix-enumerable-first-signature
Browse files Browse the repository at this point in the history
Fix Enumerable#first with argument signature
  • Loading branch information
soutaro authored Mar 16, 2021
2 parents 11bc195 + 71a5c16 commit 243a5d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/enumerable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ module Enumerable[unchecked out Elem]: _Each[Elem]
# [].first(10) #=> []
# ```
def first: () -> Elem?
| (Integer n) -> ::Array[Elem]?
| (_ToInt n) -> ::Array[Elem]

def grep: (untyped arg0) -> ::Array[Elem]
| [U] (untyped arg0) { (Elem arg0) -> U } -> ::Array[U]
Expand Down
14 changes: 14 additions & 0 deletions test/stdlib/Enumerable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ def each
end
end

class TestEmptyEnumerable
include Enumerable

def each
end
end

testing "::Enumerable[String]"

def test_inject
Expand All @@ -151,4 +158,11 @@ def test_inject
memo + item
end
end

def test_first
assert_send_type '() -> ::String?' , TestEnumerable.new, :first
assert_send_type '() -> ::String?' , TestEmptyEnumerable.new, :first
assert_send_type '(ToInt n) -> ::Array[::String]' , TestEnumerable.new, :first, ToInt.new(42)
assert_send_type '(ToInt n) -> ::Array[::String]' , TestEmptyEnumerable.new, :first, ToInt.new(42)
end
end

0 comments on commit 243a5d6

Please sign in to comment.