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
Fix DelayedEvaluator's with negative arity #7435
Conversation
DelayedEvaluator procs utilising a *rest param get a negative arity value, this causes them to be evaluated in the wrong context, checking against negative arity fixes this. Signed-off-by: Mal Graty <mal.graty@googlemail.com>
Travis failure appears unrelated. |
I'm not really seeing the use case here, I'm not even sure why we support the non- |
Based on my reading of the tests the non- The use case for this change is shown by example in the |
So I wouldn't implement your feature as a modification on the DelayedEvaluator, I would make a Property subclass and implement the logic there, since that has complete control over the system. That's worked nicely into the DSL, I'm also not sure we really need explicit support for funky context spanning stuff when you can just as easily do |
I'm not sure (or at least don't understand) if that would achieve the same thing I'm aiming for, the benefit of it being a subclass of class Chef::Resource
def late(&block)
MemoizedDelayedEvaluator.new(&block)
end
end
[...]
file '/tmp/example' do
content late { non_trivial_workload_that_will_only_run_once }
end
I don't necessarily disagree, I'm just trying to support the behaviour that already existed. |
I still think this is technically a bug, but I've worked around it now by convincing myself that the Obviously this is going to be somewhat flimsy since it relies on duplicating a small about of logic from a private method inside the class Chef::Resource
def late(&block)
memo = Chef::NOT_PASSED
lazy do |r|
if memo == Chef::NOT_PASSED
memo = block.arity > 0 ? block.call(r) : r.instance_exec(&block)
else
memo
end
end
end
end |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
DelayedEvaluator
procs utilising a*rest
param get a negative arity value, this causes them to be evaluated in the wrong context, checking against negative arity fixes this.This functionality is useful when extending the DSL in cookbooks to support other kinds of
DelayedEvaluator
s. I've included the real world example that lead to discovering this case under the fold in case there's an error in approach that invalidates this use case.Custom
DelayedEvaluator
exampleReproduction