contracts.ruby
contracts.ruby copied to clipboard
Overriding a function from an included module with contracts leads to errors
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
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.
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
@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.