Shopify / tapioca

The swiss army knife of RBI generation
MIT License
728 stars 121 forks source link

Do not report duplicate for shim or annotations classes redefining the superclass #1912

Closed Morriar closed 4 months ago

Morriar commented 4 months ago

Motivation

Sometimes we want to use shims to define the parent class that Tapioca may have missed. (Example 1, 2)

Consider this file generated by Tapioca for a gem:

# sorbet/rbi/gems/foo@1.0.0.rbi
class Foo
end

The user knows that Foo actually inherits from Baz and wants to fix this in a shim:

# sorbet/rbi/shims/foo.rbi
class Foo < Bar
end

Tapioca check-shims command will report a useless duplicated shims, yet this redefinition should be allowed:

          Duplicated RBI for ::Foo:
           * sorbet/rbi/shims/foo.rbi:1:0-2:3
           * sorbet/rbi/gems/foo@1.0.0.rbi:1:0-2:3

Implementation

Before reporting a shim class as a duplicate, we should check if it redefines the super class compared to the definitions we can find in the generated files.

Tests

See automated tests.