rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Add support for `alias $x $y`

Open sampersand opened this issue 2 years ago • 2 comments

(Originally a discussion, #1611, I think this is more apt as an issue).

One of the lesser-known facts of ruby is you can also use alias to alias global variables to one another, such as alias $LOAD_PATH $:.

I propose we support this syntax in RBS (it'd be useful for require 'English'). It's very, very niche, but should be supported eventually for completeness.

sampersand avatar Nov 24 '23 22:11 sampersand

Shunt to the back of the backlog?

sampersand avatar Nov 24 '23 22:11 sampersand

I understand we need it for completeness, but I don't think it's a priority because it's niche...

I'm not against implementing it if someone can send a PR. The outline would be:

  1. Add a syntax AST::Declarations::GlobalAlias or something?
  2. Implement parser
  3. Add a method to resolve type of global like Environment#global_type: (Symbol) -> Types::t?
  4. Need a validation to reject circular definition

soutaro avatar Nov 27 '23 01:11 soutaro