Skip to content

Raise when type parameters collide during sig to RBS translation - #1017

Open
Hashim1999164 wants to merge 6 commits into
Shopify:mainfrom
Hashim1999164:fix/rbs-type-param-shadowing
Open

Hashim1999164 wants to merge 6 commits into
Shopify:mainfrom
Hashim1999164:fix/rbs-type-param-shadowing

Conversation

@Hashim1999164

@Hashim1999164 Hashim1999164 commented Aug 18, 2026 •

Copy link
Copy Markdown

Summary

  • RBS type variables shadow constants and class type members that share the same name, so a translated sig can fail to parse or drop a type error
  • When a method type parameter collides with a constant path or class type member in the same signature, raise an error that asks the user to rename the type parameter

Closes #1012

Test plan

  • bundle exec rake test

@Hashim1999164
Hashim1999164 requested a review from a team as a code owner August 18, 2026 18:44
@jesse-shopify

Copy link
Copy Markdown
Contributor

My concern with this is renaming a user's type name can lead to confusion if that name is surfaced later. I'm thinking a better strategy will be to raise an error suggesting the user rename to avoid the collision. That keeps the user in control and the names consistent.

@Hashim1999164

Copy link
Copy Markdown
Author

@jesse-shopify hi, i understand your concern. Can you please take it up from here. I wint be available upcoming few days. Thanks

@Hashim1999164 Hashim1999164 changed the title Rename colliding type parameters when translating sigs to RBS Raise when type parameters collide during sig to RBS translation Aug 26, 2026
@Hashim1999164

Copy link
Copy Markdown
Author

@jesse-shopify I switched this to raise instead of renaming. The error asks the user to rename the type parameter so the original names stay consistent and they stay in control.

@Hashim1999164

Copy link
Copy Markdown
Author

@jesse-shopify yeah that makes sense. dropped the rename approach. it raises now and tells you to rename the type param yourself so names stay consistent.

@jesse-shopify
jesse-shopify force-pushed the fix/rbs-type-param-shadowing branch from 0638b0a to 4482ddd Compare September 16, 2026 22:17
Assign proc_returns and proc_bind to locals before visit_type so Sorbet
can narrow T.nilable(RBI::Type) down to RBI::Type.
@Hashim1999164

Copy link
Copy Markdown
Author

@jesse-shopify CI was red on a Sorbet nilable thing for proc_returns / proc_bind. pushed a tiny fix that assigns them to locals before visit_type so the type narrows. should be green now

…shadowing

# Conflicts:
#	lib/spoom/sorbet/translate/sorbet_sigs_to_rbs_comments.rb
@Hashim1999164

Copy link
Copy Markdown
Author

@jesse-shopify yeah this PR already raises instead of renaming, just had to rebase through a conflict on main. should be good now.

@Hashim1999164

Copy link
Copy Markdown
Author

@jesse-shopify any update on this one? it's approved and rebased, just checking if anything else is needed before merge

@Hashim1999164

Copy link
Copy Markdown
Author

@jesse-shopify any update on this? still approved on my side, just checking if its waiting on anything else to merge

@jesse-shopify

Copy link
Copy Markdown
Contributor

This is still failing CI. I hope to look at it later today.

@Hashim1999164

Copy link
Copy Markdown
Author

@jesse-shopify fixed the CI typecheck fail. ClassOf uses singular type_parameter in current RBI, so the walker was calling a method that doesnt exist. also merged latest main. should be green now.

RBI::Type::ClassOf exposes type_parameter, not type_parameters.
@Hashim1999164
Hashim1999164 force-pushed the fix/rbs-type-param-shadowing branch 2 times, most recently from 511717f to ab679b4 Compare October 8, 2026 16:10
@Hashim1999164

Copy link
Copy Markdown
Author

@jesse-shopify one more thing: the Ruby workflow on the latest commit is waiting on maintainer approval for fork PRs (action_required). once that run is approved it should pick up the typecheck fix.

This branch has not been deployed

No deployments
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.

srb sigs translate: type parameter shadows a type name used in the same signature

2 participants