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

give _ToProc#to_proc a return type #1223

Merged
merged 1 commit into from
Feb 6, 2023
Merged

give _ToProc#to_proc a return type #1223

merged 1 commit into from
Feb 6, 2023

Conversation

ParadoxV5
Copy link
Contributor

I don’t know what purpose are the interfaces in builtin.rbs, but I do use them for implicit conversion. The return of _ToProc#to_proc, however, is untyped and I cannot see why. This is the contract for implicit conversion to a block when prefixed with & (an_array.map(&a_to_proc)).

@ParadoxV5
Copy link
Contributor Author

ParadoxV5 commented Feb 4, 2023

[Discussion] just typing it as Proc isn’t very useful since RBS has “Proc type”s.

  • We could make it _ToProc[^(specific_arg_types) -> specific_return type] so one can specify the resulting Proc’s contract.
  • The current solution is to write a custom interface that defines the desired contract: def to_proc: ^(specific_arg_types) -> specific_return type.

Regardless of which bullet point to adopt, _ToProc#to_proc doesn’t make sense not having a return type – unless _ToProc shouldn’t exist fundamentally.

@soutaro
Copy link
Member

soutaro commented Feb 6, 2023

Thanks @ParadoxV5,

Having Proc is an improvement while it doesn't make much sense, as you said. It makes sense that passing a proc type to the type parameter, but still it's not very useful because we don't have something to express the constraints on the arguments of a proc/method.

@soutaro soutaro added this to the RBS 3.0 milestone Feb 6, 2023
@soutaro soutaro merged commit d631c0a into ruby:master Feb 6, 2023
@ParadoxV5 ParadoxV5 mentioned this pull request Nov 20, 2023
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.

2 participants