-
Notifications
You must be signed in to change notification settings - Fork 82
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
Strange issue with Contracts 0.11.0 interaction with lambdas #238
Comments
That's weird. This gist works as expected for me and prints out |
Thanks for checking this @egonSchiele ! Super-weird. I took your example and ran it inside a very similar irb environment to our end-app, and it worked. I then tweaked it to make it closer to our failing code: require "contracts"
module Foo
module Bar
include Contracts
Contract String => Func[Num => Num]
def self.test(some_arg)
return lambda { |x|
return x + 1
}
end
def self.print_incr
func = test("foo")
p func[1]
end
end
end
Foo.print_incr That worked too. We run in JRuby - whatever is going wrong I think is very deep in the runtime... Thanks for looking into it! I think if you can't reproduce we will have to close this? |
Hi Alexander , When you actually call that function, does it work or fail (regardless of I'm asking since I am assuming that we are wrapping returned proc into the
|
Hey @alex-fedorov - that's the odd thing, the lambda is not callable. In my downstream code where I try to figure out the lambda's arity, I get this error:
|
@alexanderdean As I thought. We are wrapping lambda over here: https://github.com/egonSchiele/contracts.ruby/blob/master/lib/contracts/call_with.rb#L90-L92 Therefore calling that lambda would work just fine, but not |
Ah! I think I understand now. The contract on the lambda-generating function implies some kind of wrapping of the returned lambda, otherwise how can the contract of that lambda be enforced? |
Exactly! |
The strange thing is that this test case is working: require "contracts"
module Foo
module Bar
include Contracts
Contract String => Func[Num => Num]
def self.test(some_arg)
return lambda { |x|
return x + 1
}
end
def self.print_arity
func = test("foo")
p func.arity
end
end
end
Foo.print_arity Not sure what I am doing wrong... |
First off apologies if this has been fixed in a more recent version; we use 0.11.0 at Snowplow.
In Snowplow we have a module function:
Now the strange thing is that when we call the function from elsewhere in the module like:
Then the value of
fix_filenames_lambda
is set to theContract
- it is of classContract
- rather than set to the lambda (of classProc
).Very odd! Removing the
Contract
assignment line fixes it.The text was updated successfully, but these errors were encountered: