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

Protect nilable procs with parenthesis when translating to RBS #397

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Jan 14, 2025

When translating this RBI signature:

sig { params(x: T.nilable(T.proc.returns(Foo)) }
def foo(x); end

We need to put the proc into parenthesis to keep the current semantics:

def foo: ((^-> Foo)? x) -> void

Otherwise we end up with the return type of the block being nilable rather than the proc itself:

def foo: (^-> Foo? x) -> void

@Morriar Morriar added the bugfix Fix a bug label Jan 14, 2025
@Morriar Morriar self-assigned this Jan 14, 2025
@Morriar Morriar requested a review from a team as a code owner January 14, 2025 21:34
@@ -885,7 +885,13 @@ def visit_attached_class(type)

sig { params(type: Type::Nilable).void }
def visit_nilable(type)
if type.type.is_a?(Type::Proc)
Copy link
Member

Choose a reason for hiding this comment

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

NIT: We're repeating type.type 3 times. Can we pull it into a local and reuse?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Extracted in local variable inner 👍

@Morriar Morriar force-pushed the at-rbs-nilable-procs branch 2 times, most recently from 83ad5b6 to 0614069 Compare January 15, 2025 15:20
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar Morriar force-pushed the at-rbs-nilable-procs branch from 0614069 to 08b26c2 Compare January 15, 2025 15:27
@Morriar Morriar merged commit e9e5148 into main Jan 15, 2025
8 checks passed
@Morriar Morriar deleted the at-rbs-nilable-procs branch January 15, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fix a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants