sorbet / sorbet-typed

A central repository for sharing type definitions for Ruby gems
https://sorbet.org/docs/rbi#hand-written-rbis-for-gems
Apache License 2.0
382 stars 121 forks source link

Type Elem must be re-declared in Bundler::EndpointSpecification #105

Open panthomakos opened 5 years ago

panthomakos commented 5 years ago

I am getting this error after updating sorbet-typed and I am unsure how to resolve the issue:

./sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi:1218: Type Elem declared by parent T.class_of(Gem::Specification) must be re-declared in T.class_of(Bundler::EndpointSpecification) https://srb.help/5036
    1218 |class Bundler::EndpointSpecification < Gem::Specification
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    https://github.com/sorbet/sorbet/tree/16d69282147e20e65490971bf2986ac6fa54de23/rbi/stdlib/gem.rbi#L207: Elem declared in parent here
     207 |class Gem::Specification < Gem::BasicSpecification
                ^^^^^^^^^^^^^^^^^^
jasnow commented 5 years ago

What happens when you run this: srb rbi suggest-typed

connorshea commented 5 years ago

It's really weird that the bundler.rbi would cause that but not cause it in sorbet-typed itself :/

connorshea commented 5 years ago

Are you on the latest version of sorbet? I'm not seeing this error :?

connorshea commented 5 years ago

Oh it seems to happen if you have the bundler.rbi set to strong or strict. It won't error if it's set to true.

aisamanra commented 5 years ago

We've temporarily reverted the change that caused this—that way, we can figure out what caused this situation to arise in the first place before re-merging the PR.

connorshea commented 5 years ago

I'm still confused as to where the Elem is supposed to be coming from :?

Also, if you want to get rid of the gem.rbi in your project you'll need to delete it yourself. Sorbet doesn't seem to delete files if they're in sorbet-typed, it only overwrites existing files or adds them.

connorshea commented 5 years ago

ok, so it looks like Gem::Specification does indeed extend Enumerable in hidden.rbi, which would be why there's an issue that CI didn't pick up, because CI doesn't generate any hidden definitions.

class Gem::Specification
  extend ::Enumerable
end

So when I removed the explicit extend Enumerable for Specification in #92, it fixed the problem in CI but not when actually using Sorbet.

connorshea commented 5 years ago

hm, actually this might happen regardless of whether gem.rbi is there? It seems to be entirely dependent on the typing level of bundler.rbi. So this problem is probably just caused by bundle exec srb rbi sorbet-typed not also running suggest-typed. At least, kind of.

panthomakos commented 5 years ago

Running suggest-typed downgrades the file to typed: true and resolves the issue. It seems as though that file should be able to have a higher strictness though?