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

KeywordArgs deficiencies? #282

Open
indigoviolet opened this issue Dec 21, 2017 · 0 comments
Open

KeywordArgs deficiencies? #282

indigoviolet opened this issue Dec 21, 2017 · 0 comments

Comments

@indigoviolet
Copy link
Contributor

indigoviolet commented Dec 21, 2017

The KeywordArgs contract appears to have two deficiencies:

  1. A missing arg with a Maybe[] contract is valid despite not being declared optional
[9] development (main)> kk = Contracts::KeywordArgs[a: Contracts::Maybe[String]]
[10] development (main)> kk.valid?({})
=> true

In practice, this is often not an issue because the function definition would be like

Contract Contracts::KeywordArgs[a: Contracts::Maybe[String]]
def foo(a: )
end

and Ruby would enforce the presence of a.

However this would break in the more esoteric case of

Contract Contracts::KeywordArgs[a: Contracts::Maybe[String]]
def foo(**kwargs)
end
  1. Default values for optional args are not validated by Contracts
[6] development (main)> module Foo
[6] development (main)*   Contract KeywordArgs[a: Optional[String]] => Any
[6] development (main)*   def self.foo(a: 2)
[6] development (main)*   end
[6] development (main)* end

[7] development (main)> Foo.foo
=> nil
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

1 participant