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

Add implicitly-returns-nil annotations #1226

Merged
merged 1 commit into from
Feb 8, 2023
Merged

Add implicitly-returns-nil annotations #1226

merged 1 commit into from
Feb 8, 2023

Conversation

soutaro
Copy link
Member

@soutaro soutaro commented Feb 8, 2023

The annotation tells the Array#[] and Hash#[] may return nil.

RBS itself doesn't do anything for this annotation. The type checkers may give precise types of the methods with the annotations.

The annotation tells the `Array#[]` and `Hash#[]` may return `nil`.
@soutaro soutaro added this to the RBS 3.0 milestone Feb 8, 2023
@soutaro soutaro merged commit ea495e2 into master Feb 8, 2023
@soutaro soutaro deleted the add-annotations branch February 8, 2023 07:14
tk0miya added a commit to tk0miya/rbs that referenced this pull request Sep 17, 2023
@hjwylde
Copy link
Contributor

hjwylde commented Jun 25, 2024

Hey @soutaro, just had a quick question if you don't mind; which cases are you intending this annotation to be used for? We have a user asking whether Array#first should also be annotated with {implicitly-returns-nil}. I've answered that I suspect it is an intentional design choice that it's only added to accesses ([]), but I'd just like to double check with you to find out for certain.

@soutaro
Copy link
Member Author

soutaro commented Jun 26, 2024

@hjwylde Hi! Adding the annotation to Array#first and likes would make sense. I had planned to implement support for the annotation in Steep to test the type checking experience with it, but not finished yet...

@ParadoxV5
Copy link
Contributor

I instead prefer something more explicit… a way for fixed-size tuples and records to narrow the return of their #[] and co.… and possibly expand to variable-size Arrays and Hashes.

@hjwylde
Copy link
Contributor

hjwylde commented Jun 30, 2024

Thanks @soutaro, I'll make a pull request to add a few more for the user then :).

I think I do half agree with @ParadoxV5's that there are use-cases for more elaborate contracts (and I've had some ideas on others for RubyMine), but I think implicitly-returns-nil is good to start and usable right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants