Skip to content

Commit 52fc102

Browse files
authored
Bugfix: newsize not defined in error message (#868)
Looking at the history, this is pretty old code, and the special case `v <: StaticArray` seems unnecessary now — the compiler should have no trouble computing `length(v)` as a constant and eliminating the branch when `v` is a static array.
1 parent 71c1000 commit 52fc102

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/indexing.jl

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -348,25 +348,14 @@ end
348348
j += 1
349349
end
350350

351-
if v <: StaticArray
352-
@boundscheck if Length(v) != prod(linearsizes)
353-
return DimensionMismatch("tried to assign $(length(v))-element array to $newsize destination")
354-
end
355-
quote
356-
@_propagate_inbounds_meta
357-
$(exprs...)
358-
return a
359-
end
360-
else
361-
quote
362-
@_propagate_inbounds_meta
363-
if length(v) != $(prod(linearsizes))
364-
newsize = $linearsizes
365-
throw(DimensionMismatch("tried to assign $(length(v))-element array to $newsize destination"))
366-
end
367-
$(exprs...)
368-
return a
351+
quote
352+
@_propagate_inbounds_meta
353+
if length(v) != $(prod(linearsizes))
354+
newsize = $linearsizes
355+
throw(DimensionMismatch("tried to assign $(length(v))-element array to $newsize destination"))
369356
end
357+
$(exprs...)
358+
return a
370359
end
371360
end
372361

test/indexing.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ using StaticArrays, Test
142142
# SOneTo
143143
@test (mm = MMatrix{2,2,Int}(undef); mm[SOneTo(1),:] = sm[SOneTo(1),:]; (@inferred getindex(mm, SOneTo(1), :))::MMatrix == @MMatrix [1 3])
144144
@test (mm = MMatrix{2,2,Int}(undef); mm[:,SOneTo(1)] = sm[:,SOneTo(1)]; (@inferred getindex(mm, :, SOneTo(1)))::MMatrix == @MMatrix [1;2])
145+
146+
# #866
147+
@test_throws DimensionMismatch setindex!(MMatrix(SA[1 2; 3 4], SA[3,4], 1, SA[1,2,3]))
148+
@test_throws DimensionMismatch setindex!(MMatrix(SA[1 2; 3 4], [3,4], 1, SA[1,2,3]))
145149
end
146150

147151
@testset "3D scalar indexing" begin

0 commit comments

Comments
 (0)