Skip to content

Commit

Permalink
error message for indexing with BitArray (#38689)
Browse files Browse the repository at this point in the history
* error message for indexing with BitArray

* modify show_index instead

* use BitMatrix in error message

* update error msg

* BitVector !?
  • Loading branch information
JeffFessler authored Dec 9, 2020
1 parent a813a6e commit a1106b8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ showerror(io::IO, ex) = show(io, ex)

show_index(io::IO, x::Any) = show(io, x)
show_index(io::IO, x::Slice) = show_index(io, x.indices)
show_index(io::IO, x::LogicalIndex) = show_index(io, x.mask)
show_index(io::IO, x::LogicalIndex) = summary(io, x.mask)
show_index(io::IO, x::OneTo) = print(io, "1:", x.stop)
show_index(io::IO, x::Colon) = print(io, ':')

Expand Down
2 changes: 1 addition & 1 deletion test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2842,7 +2842,7 @@ end
b = IOBuffer()
showerror(b, err)
@test String(take!(b)) ==
"BoundsError: attempt to access 2×2 Matrix{Float64} at index [10, Bool[1, 1]]"
"BoundsError: attempt to access 2×2 Matrix{Float64} at index [10, 2-element BitVector]"

# Also test : directly for custom types for which it may appear as-is
err = BoundsError(x, (10, :))
Expand Down
2 changes: 2 additions & 0 deletions test/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ let undefvar
@test err_str == "BoundsError: attempt to access 3-element Vector{$Int} at index [-2, 1]"
err_str = @except_str [5, 4, 3][1:5] BoundsError
@test err_str == "BoundsError: attempt to access 3-element Vector{$Int} at index [1:5]"
err_str = @except_str [5, 4, 3][trues(6,7)] BoundsError
@test err_str == "BoundsError: attempt to access 3-element Vector{$Int} at index [6×7 BitMatrix]"

err_str = @except_str Bounded(2)[3] BoundsError
@test err_str == "BoundsError: attempt to access 2-size Bounded at index [3]"
Expand Down

0 comments on commit a1106b8

Please sign in to comment.