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

Bugfix: newsize not defined in error message #868

Merged
merged 1 commit into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,25 +348,14 @@ end
j += 1
end

if v <: StaticArray
@boundscheck if Length(v) != prod(linearsizes)
return DimensionMismatch("tried to assign $(length(v))-element array to $newsize destination")
end
quote
@_propagate_inbounds_meta
$(exprs...)
return a
end
else
quote
@_propagate_inbounds_meta
if length(v) != $(prod(linearsizes))
newsize = $linearsizes
throw(DimensionMismatch("tried to assign $(length(v))-element array to $newsize destination"))
end
$(exprs...)
return a
quote
@_propagate_inbounds_meta
if length(v) != $(prod(linearsizes))
newsize = $linearsizes
throw(DimensionMismatch("tried to assign $(length(v))-element array to $newsize destination"))
end
$(exprs...)
return a
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ using StaticArrays, Test
# SOneTo
@test (mm = MMatrix{2,2,Int}(undef); mm[SOneTo(1),:] = sm[SOneTo(1),:]; (@inferred getindex(mm, SOneTo(1), :))::MMatrix == @MMatrix [1 3])
@test (mm = MMatrix{2,2,Int}(undef); mm[:,SOneTo(1)] = sm[:,SOneTo(1)]; (@inferred getindex(mm, :, SOneTo(1)))::MMatrix == @MMatrix [1;2])

# #866
@test_throws DimensionMismatch setindex!(MMatrix(SA[1 2; 3 4], SA[3,4], 1, SA[1,2,3]))
@test_throws DimensionMismatch setindex!(MMatrix(SA[1 2; 3 4], [3,4], 1, SA[1,2,3]))
end

@testset "3D scalar indexing" begin
Expand Down