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

Sorbet doesn't notice gems defined in gemspec file #1238

Closed
connorshea opened this issue Jul 9, 2019 · 4 comments
Closed

Sorbet doesn't notice gems defined in gemspec file #1238

connorshea opened this issue Jul 9, 2019 · 4 comments
Labels
bug Something isn't working

Comments

@connorshea
Copy link
Contributor

connorshea commented Jul 9, 2019

Input

I've created an example repository to demonstrate the problem: https://github.com/connorshea/sorbet-gemspec-issue-example

Note how the yard.rbi file changes with this commit that adds yard explicitly in the Gemfile.

If you use a gemspec to define dependencies, instead of defining the dependencies in a Gemfile explicitly, Sorbet (I suspect gem_loader.rb specifically) doesn't seem to find as many module definitions. I assume this is because gem_loader.rb for whatever reason doesn't handle the gemspec keyword correctly in a Gemfile.

Works:

# Gemfile
source "https://rubygems.org"

gem 'yard'

Doesn't work:

# Gemfile
source "https://rubygems.org"

gemspec
# example.gemspec
Gem::Specification.new do |s|
  s.name        = 'example'
  s.version     = '0.0.1'
  s.date        = '2019-07-27'
  s.summary     = "Example"
  s.description = "A simple hello world gem"
  s.authors     = ["Connor Shea"]
  s.files       = ["lib/example.rb"]
  s.homepage    =
    'https://rubygems.org/gems/example'
  s.license       = 'MIT'

  s.add_dependency 'yard'
end

Observed output

The file at sorbet/rbi/gems/yard.rbi is only 300 lines vs. 1200 lines when yard is required explicitly via the Gemfile.

Expected behavior

I'd expect Sorbet to output the same yard.rbi either way.

It doesn't seem like any other gems' generated rbis differ when Sorbet is initialized, only YARD (and presumably any other gems that have requires specified in gem_loader.rb. I think this does actually effect all gems defined in a gemspec. If they're not explicitly required by a file in the project, Sorbet won't notice them. Whereas if they're defined in the Gemfile, Sorbet will notice them regardless of any require.

@connorshea connorshea added bug Something isn't working unconfirmed This issue has not yet been confirmed by the Sorbet team labels Jul 9, 2019
@connorshea
Copy link
Contributor Author

You can also see this issue in the sorbet/rbi/gems/ directory with Sord and Parlour. Sord has the problem where YARD's rbi isn't fully generated and Parlour has the problem where not all the gems depended on in the gemspec have their rbis generated.

@connorshea connorshea changed the title gem_loader.rb doesn't notice gems defined in gemspec file Sorbet doesn't notice gems defined in gemspec file Jul 9, 2019
@aisamanra aisamanra removed the unconfirmed This issue has not yet been confirmed by the Sorbet team label Jul 9, 2019
@jasnow
Copy link
Contributor

jasnow commented Aug 16, 2019

Big problem

@greggroth
Copy link

I believe this is the same bug -- I've found that including a gem in a project and generating the hidden definitions does not include that gem's dependencies. I've worked around this by explicitly listing the dependencies I'm using in my project's Gemfile.

@Morriar Morriar added the srb label Aug 19, 2020
@jez
Copy link
Collaborator

jez commented Jul 27, 2022

Going to close this in favor of Tapioca

https://sorbet.org/blog/2022/07/27/srb-tapioca

@jez jez closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants