You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's an easy mistake to make to call stack(array1, array2) instead of stack([array1, array2]) - for eg., having used stack only occasionally, I just tried (something similar to) stack(1:3, 4:6), and got the error message:
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.
Stacktrace:
...
This was really confusing, and had me even checking if I'd accidentally declared a variable named stack somehow. Even looking at the docstring didn't immediately make it obvious why I was getting this particular error, until I realized that it was hitting the
stack(f, args...; [dims])
dispatch, and trying to use 1:3 as the callable f.
It would be a nice improvement to DevEx if this subtle and easy-to-make mistake had a better error message, that more directly hinted at the problem. Something like:
If you're passing multiple iterables to stack, pass them instead as a single iterable of iterables i.e. instead of stack(array1, array2), use stack([array1, array2])
Addresses #57807 to some
extent, although the error message may be improved further.
On nightly,
```julia
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
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.
```
It's an easy mistake to make to call
stack(array1, array2)
instead ofstack([array1, array2])
- for eg., having usedstack
only occasionally, I just tried (something similar to)stack(1:3, 4:6)
, and got the error message:This was really confusing, and had me even checking if I'd accidentally declared a variable named
stack
somehow. Even looking at the docstring didn't immediately make it obvious why I was getting this particular error, until I realized that it was hitting thedispatch, and trying to use
1:3
as the callablef
.It would be a nice improvement to DevEx if this subtle and easy-to-make mistake had a better error message, that more directly hinted at the problem. Something like:
At a glance,
julia/base/errorshow.jl
Line 1084 in 8efd4f4
methods_on_iterable
in errorshow.jl) seems like a convenient place to add this.The text was updated successfully, but these errors were encountered: