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

Make callable-related MethodError messages more descriptive #57815

Merged
merged 1 commit into from
Mar 19, 2025

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Mar 18, 2025

Addresses #57807 to some extent, although the error message may be improved further.

On nightly,

julia> stack(1:3, 1:3)
ERROR: MethodError: objects of type UnitRange{Int64} are not callable
Use square brackets [] for indexing an Array.
The object of type `UnitRange{Int64}` exists, but no method is defined for this combination of argument types when trying to treat it as a callable object.

The second sentence seems unrelated to the first, and the source of the error remains unclear from the message.

This PR makes the message more verbose, and provides pointers.

julia> stack(1:3, 200)
ERROR: MethodError: objects of type UnitRange{Int64} are not callable.
In case you did not try calling it explicitly, check if a UnitRange{Int64} has been passed as an argument to a method that expects a callable instead.
In case you're trying to index into the array, use square brackets [] instead of parentheses ().
The object of type `UnitRange{Int64}` exists, but no method is defined for this combination of argument types when trying to treat it as a callable object.

@jishnub jishnub added the error messages Better, more actionable error messages label Mar 18, 2025
@jishnub jishnub force-pushed the jishnub/errhint_fn branch from 54114f7 to 63779fe Compare March 19, 2025 07:47
@jishnub jishnub merged commit 4ec13f5 into master Mar 19, 2025
7 checks passed
@jishnub jishnub deleted the jishnub/errhint_fn branch March 19, 2025 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Better, more actionable error messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants