Skip to content

module_function ignores contracts #92

Open
@kliuless

Description

@kliuless

Tested on 0.7. It's possible that module_function is too magical to try to work around. In that case the docs should say not to use it. (It's probably not feasible to redefine module_function to raise an error, because it might be called before including contracts.)

module OverloadCase
  include Contracts
  include Contracts::Modules
  #extend self     # this works   
  module_function  # this doesn't 

  Contract 1 => 1
  def fact(n) 1 end

  Contract Integer => Integer
  def fact(n)
    n * fact(n-1)
  end
end

module MinCase
  include Contracts
  include Contracts::Modules
  #extend self     # this works
  module_function  # this doesn't

  Contract 1 => 1
  def fact(n) 1 end
end

if __FILE__ == $0
  p OverloadCase.fact(6) # => stack too deep
  p MinCase.fact(6)      # => violation is ignored, so 1 is returned
end

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions