Skip to content

Commit c75bf3c

Browse files
committed
New version of setindex
1 parent 94e905c commit c75bf3c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/setindex.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ Base.@propagate_inbounds function setindex(args...)
33
end
44

55
Base.@propagate_inbounds function setindex(xs::AbstractArray, v, I...)
6-
T = promote_type(eltype(xs), typeof(v))
6+
# we need to distinguish between scalar and sliced assignment
7+
I_normalized = Base.to_indices(xs, I)
8+
T = promote_type(eltype(xs), I_normalized isa Tuple{Vararg{Integer}} ? typeof(v) : eltype(v))
79
ys = similar(xs, T)
810
if eltype(xs) !== Union{}
911
copy!(ys, xs)
1012
end
11-
ys[I...] = v
13+
ys[I_normalized...] = v
1214
return ys
1315
end
1416

0 commit comments

Comments
 (0)