-
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
Contract error when mixing positional and keyword arguments with defaults #304
Comments
I don't even know how it handles positional optional arguments |
It is indeed not documented, but it works as expected when only positional arguments are used: class C
include Contracts
Contract String, String => Any
def goo(a = 'a', b = 'b')
p [a, b]
end
end
c = C.new
c.goo # Works ✔️
c.goo('a') # Works ✔️
c.goo('a', 'b') # Works ✔️ The issue seems to be in class C
include Contracts
Contract String, Any => Any
def hoo(a = 'a', b: 'b')
p [a, b]
end
end
c = C.new
c.hoo('a', b: 'b') # Works ✔️
c.hoo('a') # Works ✔️
c.hoo(b: 'b') # Works ✔️
c.hoo # Works ✔️ |
I think it's a deeper issue of lacking a contract for optional positional argument
It's fine for methods with optional arguments only coz it works like: But if optional positional argument is mixed with keyword arguments I am guessing from |
Please check #305 and see if you want to add more examples to ensure I don't break anything |
I won't merge #305 until some has tested it~ |
Thanks for the patch! I'll test it later this week. |
@PikachuEXE everything looks good! 🚀 No issues in our 4K+ file repo. |
Let me release it next week if no other PR blocking |
I forgot I don't have release right in this gem |
I’m traveling, give me a few daysOn Sep 22, 2024, at 8:38 PM, PikachuEXE ***@***.***> wrote:
I forgot I don't have release right in this gem
@egonSchiele Please release a new version 0.17.1 thx
Changes: v0.17...master
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
done |
I'm having trouble defining a contract for a method that takes two optional arguments -- a positional one and a keyword one. Consider:
The stack trace is
It seems Contracts wants me to provide the positional argument even if a default is specified in the method signature? 🤔
The text was updated successfully, but these errors were encountered: