AaronC81 / parlour

A type signature generator, merger and parser system for Sorbet and Ruby 3/Steep
MIT License
91 stars 16 forks source link

Conflict resolver doesn't handle type signatures contained in a separate RBI file to the main code #115

Open Bo98 opened 3 years ago

Bo98 commented 3 years ago

Describe the bug Sometimes type signatures are not defined inline in the main code but are defined in a separate RBI file with the same name.

For example: a file called mod.rb, which itself has a # typed: strict comment, might not actually have any type signatures stored inline but instead may have it in mod.rbi that sits alongside.

To Reproduce Create a mod.rb with the following contents:

# typed: strict

module TestModule
  def self.some_method(arg)
    puts arg
  end
end

Then create a mod.rbi with the following contents:

# typed: strict

module TestModule
  include Kernel

  sig { params(arg: String).void }
  def self.some_method(arg); end
end

Note that srb tc will pass without errors here - it picks up the RBI and merges the type signatures into the main file.

Expected behavior The Parlour conflict resolver handles this without errors.

Actual behavior

Parlour debug: Class: Registered
Parlour debug: conflict resolver: ├─ Resolving conflicts for <anonymous namespace>...
Parlour debug: conflict resolver: │  ├─ Checking children named TestModule...
Parlour debug: conflict resolver: │  │  ├─ Possible conflict between 2 objects
Parlour debug: conflict resolver: │  │  └─ Children are all mergeable; resolving automatically
Parlour debug: conflict resolver: │  ├─ Resolving children...
Parlour debug: conflict resolver: │  ├─ Resolving conflicts for TestModule...
Parlour debug: conflict resolver: │  │  ├─ Checking children named some_method...
Parlour debug: conflict resolver: │  │  │  ├─ Possible conflict between 2 objects
Parlour debug: conflict resolver: │  │  │  └─ Unable to resolve automatically; requesting manual resolution

Additional information Parlour 6.0.0

rodrigovilina commented 3 years ago

@Bo98 Is there any known workarounds? I'm having the same issue.

AaronC81 commented 3 years ago

Apologies it's taken me so long to respond to this! I totally missed the notification the first time around, it was the new comment which brought this back into my inbox.

I agree this should merge fine, I'll look into fixing this up.

@Bo98 @vaporyhumo As a workaround, you could use a .parlour file to tell the parser to include only the RBI files you'd like to merge together, which will exclude those Ruby files which it's conflicting with:

output_file:
  rbi: output.rbi

parser:
  included_paths:
    - ./lib/mod.rbi
rodrigovilina commented 3 years ago

Awesome, thanks!