-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Print a tip in MethodError #57339
Open
Bumblebee00
wants to merge
4
commits into
JuliaLang:master
Choose a base branch
from
Bumblebee00:MethodError_PrintTip_57319
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+11
−0
Open
Print a tip in MethodError #57339
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b78dc88
Improve error messages for MethodError and add tips for single-method…
Bumblebee00 3f239d0
Merge branch 'JuliaLang:master' into master
Bumblebee00 15a0bb4
Merge branch 'JuliaLang:master' into master
Bumblebee00 bec6b8f
splitting in two branches
Bumblebee00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm not sure this is quite right;
f
doesn't need to be a function in order for there to be a mismatch in the number of arguments (i.e. it could be a type or callable object), but also, I believe this tip will be printed when the correct number of arguments is provided but the sole method does not apply to them. For example, consider:As currently implemented, the error message would include
which I don't think would help a user determine the source of the issue or how to fix 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.
That is correct I didnt think about this. But could be easly resolved by also checking if the number of arguments with wich the function was called is different from the accepted arguments, like so:
can you think of other cases in wich this tip could be misleading?
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.
That's a good start but I don't think it will handle vararg signatures correctly. For example, consider:
You could use
isvatuple(m.sig)
to identify this case.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.
Yes that's true I didn't tought about those, in fact when the function method accepts vararg types it doesn't make sense to talk about the number of arguments passed. I also realized that a function with keyword arguments would wrongly trigger the tip:
bc in this case the error is caused by the first element being a float, not by the number of types.
So to wrap up this tip can be useful only when:
can you think of other cases in wich this tip could be misleading?
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.
It could actually also be helpful if the function has multiple methods, all of which take the same (fixed) number of arguments. Then one could say "You passed 1 argument but all methods of this function expect 2 arguments"
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 think there is still a useful query here, even if you have vararg. For example, using the definition
f(x::Int, y::Float64...)
from above, the error from callingf()
would be relevant to the number of arguments provided.I think something like this would cover the cases where this tip could provide some useful information:
This seems relevant even in the case of
h
as defined above that accepts keyword arguments.