Skip to content

Update Array#2987

Merged
soutaro merged 23 commits into
ruby:masterfrom
sampersand:swesterman/2026-05-22/update-Array
Jun 24, 2026
Merged

Update Array#2987
soutaro merged 23 commits into
ruby:masterfrom
sampersand:swesterman/2026-05-22/update-Array

Conversation

@sampersand

@sampersand sampersand commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

This PR completely updates Array's signatures, and rewrites the test harness to work with it.

Note that there's some # where E: ... comments strewn about in the code. This marks places where, when we eventually get around to implementing the where clause, we should implement them in the Array.

@sampersand sampersand changed the title swesterman/2026 05 22/update Array Update Array Jun 3, 2026
@sampersand sampersand force-pushed the swesterman/2026-05-22/update-Array branch 2 times, most recently from 786a245 to 31a4a54 Compare June 3, 2026 21:28
Comment thread core/array.rbs
Comment thread core/array.rbs Outdated
#
alias any? all?
def any?: () -> bool
| (_Pattern[E] pattern) -> bool

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TODO: Use RBS::Ops:_Matches

Comment thread core/array.rbs Outdated
Comment thread core/array.rbs Outdated
Comment thread core/array.rbs
Comment thread core/array.rbs
Comment thread core/array.rbs
@sampersand sampersand force-pushed the swesterman/2026-05-22/update-Array branch 2 times, most recently from 1eef064 to 0fa718e Compare June 3, 2026 21:38
@sampersand sampersand marked this pull request as ready for review June 3, 2026 21:49
@soutaro soutaro added this to the RBS 4.1 milestone Jun 4, 2026
Comment thread core/array.rbs Outdated
def bsearch: () -> ::Enumerator[E, E?]
| () { (E) -> (true | false) } -> E?
| () { (E) -> ::Integer } -> E?
def bsearch: () { (E element) -> (Numeric | bool?) } -> E?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure if this works for actual type checkers, but these definitions are not equivalent.
Returning both true | false and Integer from a block is not allowed to bsearch, I think.

@ParadoxV5 ParadoxV5 Jun 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[].bsearch { it.positive? and it } # false | Integer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

https://docs.ruby-lang.org/en/4.0/language/bsearch_rdoc.html#label-Binary+Searching

The block should not mix the modes by sometimes returning true or false and other times returning a numeric value, but this is not checked.

Comment thread core/array.rbs Outdated
@sampersand sampersand force-pushed the swesterman/2026-05-22/update-Array branch from cc52661 to 4691c6d Compare June 4, 2026 06:20
@sampersand sampersand force-pushed the swesterman/2026-05-22/update-Array branch from 2f1d30d to 21d3886 Compare June 5, 2026 03:25

@sampersand sampersand left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Did final check, should good

@sampersand sampersand force-pushed the swesterman/2026-05-22/update-Array branch from dfe3641 to a814469 Compare June 9, 2026 22:00
Comment thread core/array.rbs
# Array](rdoc-ref:Array@Methods+for+Creating+an+Array).
#
def self.[]: [U] (*U) -> ::Array[U]
def self.[]: [U] (*U) -> Array[U] # this technically returns a subclass, but `instance(self)` isn't a thing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think instance would work. However instance[U] isn't a thing.

Comment thread core/array.rbs Outdated
sampersand and others added 2 commits June 18, 2026 20:04
Co-authored-by: Soutaro Matsumoto <matsumoto@soutaro.com>
Comment thread core/array.rbs Outdated

@soutaro soutaro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@soutaro soutaro merged commit 179eee2 into ruby:master Jun 24, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants