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 RBS translation of non-block type in block position #394

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Jan 14, 2025

Consider this RBI signature:

sig { params(block: T.proc.void).void }
def foo(&block); end

The RBS equivalent to define the block type is this:

def foo: { () -> void } -> void

Now on the tricky part, RBS doesn't support anything else than an actual block type definition in block position so this would be invalid syntax:

def foo: { FOO } -> void

This becomes an issue when using RBI type aliases such as this:

FOO = T.type_alias { T.proc.void }

sig { params(block: FOO) }
def foo(&block); end

This could be changed upstream following an RFC against RBS but for now let's just ignore the case and generate the RBS as untyped:

FOO: untyped

def foo: { (?) -> untyped } -> 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:12
Copy link
Contributor

@egiurleo egiurleo left a comment

Choose a reason for hiding this comment

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

Nice. I like your prioritization here!

Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

Can't we grab the contents of the type alias and put that as the type?

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar Morriar force-pushed the at-rbs-block-alias branch from 64312e5 to 4aa8d30 Compare January 15, 2025 15:07
@Morriar
Copy link
Collaborator Author

Morriar commented Jan 15, 2025

Can't we grab the contents of the type alias and put that as the type?

The issue is that the alias can exist anywhere in the codebase include in .rbi files. We would need a global knowledge to be able to do this.

We could imagine doing this at Sorbet level or make a smarter translator that uses the code index but I only found a couple of sigs using this pattern so that's a lot of complexity for relatively low benefits.

Maybe a simpler approach would be to write a cop to spot those cases and fix them manually before running the translator.

@Morriar Morriar merged commit 3ac48c6 into main Jan 15, 2025
8 checks passed
@Morriar Morriar deleted the at-rbs-block-alias branch January 15, 2025 15:15
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