Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Array#concat signature on subclasses #648

Merged
merged 1 commit into from
Mar 16, 2021
Merged
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
2 changes: 1 addition & 1 deletion core/array.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ class Array[unchecked out Elem] < Object
#
# See also Array#+.
#
def concat: (*::Array[Elem] arrays) -> ::Array[Elem]
def concat: (*::Array[Elem] arrays) -> self

# Returns the number of elements.
#
Expand Down
2 changes: 2 additions & 0 deletions test/stdlib/Array_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ def test_compact
def test_concat
assert_send_type "(Array[Integer], Array[Integer]) -> Array[Integer]",
[1,2,3], :concat, [4,5,6], [7,8,9]
assert_send_type "(Array[Integer], Array[Integer]) -> self",
Class.new(Array).new, :concat, [4,5,6], [7,8,9]
Comment on lines +220 to +221
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t know why even in without changing signature, this added test passed. But adding it makes better, I think.
Please tell me a way if rbs have something to ensure it. 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. The test passes because Class.new(Array).new.is_a?(Array) holds. The runtime type checker can be improved...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮 Thank you for letting me know the why!

end

def test_count
Expand Down