-
Notifications
You must be signed in to change notification settings - Fork 15
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
Issue 519 method arg check #527
Conversation
@@ -44,6 +44,10 @@ pub fn convert_method_call( | |||
let found = mk | |||
.class_dict | |||
.lookup_method(receiver_ty, method_name, locs)?; | |||
|
|||
let total_args = args.unnamed.len() + args.named.len(); | |||
validate_argument_length(total_args, &found.sig.params)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[IMO]
It's good to validate argument length before types checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[comment]
This PR makes shiika can also catch fewer argument error.
It's not in scope of this issue and if you don't want to catch fewer argument error, please notify me.
I'll change this PR to contain changes for make shiika catches extra argument error only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reverted it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self reviewed
05c654f
to
9ac7ad2
Compare
@@ -162,6 +166,18 @@ pub fn arrange_named_args<'a>( | |||
Ok(v) | |||
} | |||
|
|||
/// Check if number of arguments matches to the params. | |||
fn validate_argument_length(total_args: usize, params: &[MethodParam]) -> Result<()> { | |||
if total_args > params.len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[NOTE]
I want to validate fewer argument also but after make this comparison to total_args != params.len()
, the change breaks tests.
I'll work for validating fewer argument error in next issue if you like it.
In that case, please notify me and assign me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to validate fewer argument also but after make this comparison to total_args != params.len(), the change breaks tests.
Yes, that's because a parameter can have a default value.
class A
def self.foo(a: Int, b = 2); end
end
A.foo(1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhhh I got it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self reviewed
@yhara Please review this whenever it's convenient for you. |
Thank you for your PR! Implementation is already perfect but how about adding a error report?
|
I'll try that in a few days! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self reviewed
Merged. Thanks! |
close #519
What I did:
Add functionality to raise argument error for extraneous arguments