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

Undefined variable in a lambda causes a segmentation fault #225

Closed
max11D opened this issue Feb 9, 2016 · 2 comments
Closed

Undefined variable in a lambda causes a segmentation fault #225

max11D opened this issue Feb 9, 2016 · 2 comments

Comments

@max11D
Copy link

max11D commented Feb 9, 2016

It seems I made a typo in a contract and broke Rails.

Contract KeywordArgs[
        payment_method: Or[*Cart::PAYMENT_METHODS],
        country: lambda { |x| Duty.get_supported_duty_countries.keys.include?(key) },
        coupon: Optional[Or[Coupon, String, nil]]
    ] => Numeric
def duty(payment_method:, country:, coupon: nil)
    # ...
end

Note that the contract on the "country" variable uses a "key" variable that isn't defined. While this is definitely my fault, I figure it probably shouldn't be causing a segmentation fault. I can attach the resulting dump if the issue isn't easily reproduceable. Doing the same in a lambda outside the contract fails gracefully.

Duty.get_supported_duty_countries returns a hash.

@egonSchiele
Copy link
Owner

Hey @max11D ,

I came up with this standalone snippet similar to your code:

require "contracts"
include Contracts

Contract KeywordArgs[bar: lambda { |x| keys.include?(x) }] => Any
def foo(bar:)
  p bar
end

foo(bar: 1)

This throws an error like I would expect:

test.rb:4:in `block in <main>': undefined local variable or method `keys' for main:Object (NameError)

contracts.ruby is a pure Ruby gem, so I don't think this segfault is coming from here. It's more likely related to some other library you are using (maybe Rails) that has C extensions.

@egonSchiele
Copy link
Owner

I'm going to close this issue, please re-open if it turns out to be contracts after all.

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

2 participants