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

Overriding a function from an included module with contracts leads to errors #243

Open
indigoviolet opened this issue Nov 24, 2016 · 3 comments

Comments

@indigoviolet
Copy link
Contributor

ContractError:
It looks like you are trying to use pattern-matching, but
multiple definitions for function '<function name here>' have the same
contract for input parameters:

None => String
None => String

if I do something like:

module Foo
   Contract None => String
   def foo

...

class Bar
   include Foo
    
   def foo

@indigoviolet indigoviolet changed the title Overriding a function from an included module with contracts leads to errors` Overriding a function from an included module with contracts leads to errors Nov 24, 2016
@indigoviolet
Copy link
Contributor Author

In addition, that error message is not very useful, since it just repeats the (repeated) contract - would be more useful to show the offending code.

@egonSchiele
Copy link
Owner

I can't reproduce this, is there something I'm missing?

require "contracts"
include Contracts

module Foo
   Contract None => String
   def foo
    "hi"
   end
end

class Bar
  include Foo

  Contract None => String
  def foo
    "adit"
  end
end

p Bar.new.foo

@leoarnold
Copy link

@egonSchiele I am currently working on a Rails project where the same ContractError will appear, but only when running RSpec tests via Spring preloader. So far I have not been able to track down the cause. I just need to comment out a few contracts to get RSpec to run. As the project is proprietary, I can't post the code here and so far I have not worked out a minimal example, but if you have any idea what role Spring is playing here, then maybe we could find one faster.

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

No branches or pull requests

3 participants