-
-
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
Give a better error than BoundsError in multiple assignment #7978
Labels
error handling
Handling of exceptions by Julia or the user
Comments
JeffBezanson
changed the title
Give a better error than BoundsError
Give a better error than BoundsError in multiple assignment
Aug 14, 2014
The output for this is now In [3]: a,b,c = 1,2
Out [3]: ERROR: LoadError: BoundsError: attempt to access (1,2)
at index [3]
while loading In[19], in expression starting on line 1
in indexed_next at no file which is much more helpful. Thanks @vtjnash! |
This has maybe regressed? In 0.6: julia> foo() = 1
foo (generic function with 1 method)
julia> x, y = foo()
ERROR: BoundsError
Stacktrace:
[1] indexed_next(::Int64, ::Int64, ::Bool) at ./tuple.jl:56 |
Doesn't look like that function was ever fixed. This patch fixes that case, but needs tests. diff --git a/base/tuple.jl b/base/tuple.jl
index 1ffc85f9c4..b08da0ca75 100644
--- a/base/tuple.jl
+++ b/base/tuple.jl
@@ -57,7 +57,7 @@ end
# while reducing to plain next() for arbitrary iterables.
indexed_next(t::Tuple, i::Int, state) = (t[i], i+1)
indexed_next(a::Array, i::Int, state) = (a[i], i+1)
-indexed_next(I, i, state) = done(I,state) ? throw(BoundsError()) : next(I, state)
+indexed_next(I, i, state) = done(I, state) ? throw(BoundsError(I, state)) : next(I, state)
# Use dispatch to avoid a branch in first
first(::Tuple{}) = throw(ArgumentError("tuple must be non-empty")) |
fredrikekre
pushed a commit
that referenced
this issue
Oct 16, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems like we could give a better error here:
This example is trivial, but a use case that was much more frustrating was along the lines of
In which case you spend too much time checking if
x
is inbounds, and then ifmethodB
is somehow out of bounds, etc.The text was updated successfully, but these errors were encountered: