Skip to content

Commit 7bec296

Browse files
dourouc05fredrikekre
authored andcommitted
Better error message for deprecated scalar-fill indexed assignment, fixes #29266 (#31085)
1 parent cef655a commit 7bec296

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

base/indices.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ function setindex_shape_check(X::AbstractArray{<:Any,2}, i::Integer, j::Integer)
231231
end
232232
end
233233

234+
setindex_shape_check(::Any...) =
235+
throw(ArgumentError("indexed assignment with a single value to many locations is not supported; perhaps use broadcasting `.=` instead?"))
236+
234237
# convert to a supported index type (array or Int)
235238
"""
236239
to_index(A, i)

test/broadcast.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,15 @@ let n = 1
684684
@test ceil.(Int, 1 ./ (1,)) == (1,)
685685
end
686686

687+
# Issue #29266
688+
@testset "deprecated scalar-fill .=" begin
689+
a = fill(1, 10)
690+
@test_throws ArgumentError a[1:5] = 0
691+
692+
x = randn(10)
693+
@test_throws ArgumentError x[x .> 0.0] = 0.0
694+
end
695+
687696

688697
# lots of splatting!
689698
let x = [[1, 4], [2, 5], [3, 6]]

0 commit comments

Comments
 (0)