Skip to content

Add support for .rbi type stub files#44

Open
nelhage wants to merge 9 commits intomasterfrom
nelhage-typestub
Open

Add support for .rbi type stub files#44
nelhage wants to merge 9 commits intomasterfrom
nelhage-typestub

Conversation

@nelhage
Copy link
Copy Markdown
Contributor

@nelhage nelhage commented Sep 11, 2017

This PR is a work-in-progress not for merge yet, but it's in a "kind of working" state so I wanted to open it for discussion.

The goal here is to allow specifying type signatures in a .rbi file that sits alongside a .rb file, so that we can play with adding type annotations without having to upgrade our Ruby runtime and rubocop and everyone's editor tooling all at once.

The shape of this is very early and open to change, especially if the github folks have thoughts. The current in-progress implementation looks something like:

  • Whenever we load a .rb file, we look for a corresponding .rbi file, and load it afterwards, if it exists
  • It is an error to define a type signature for a method in both the .rb and .rbi file
  • The .rbi file must fully-annotate all methods defined in it
  • Redefining a symbol from a .rbi file in a later .rb is disallowed
  • (planned, unimplemented) .rbi files must only contain class, module, method, and ivar definitions
  • (planned, unimplemented) writing a type signature in both a .rb and a .rbi is disallowed

Test case are included for each of the implemented bullet points.

I expect that rolling more prototype-resolution into the define phase will simplify this feature substantially; we can resolve stub vs normal prototypes there, and then reduce the duplication between process and prototype_from_method_entry and in general stop ever dealing with the Node form of prototypes in eval.rs.

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.

1 participant