-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
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 ofstack(array1, array2), usestack([array1, array2])
At a glance,
Line 1084 in 8efd4f4
| function methods_on_iterable(io, ex, arg_types, kwargs) |
methods_on_iterable in errorshow.jl) seems like a convenient place to add this.