Skip to content

Commit afb9ad4

Browse files
authored
add informative error message for map!(f, array) (#35186)
1 parent 60323b6 commit afb9ad4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

base/abstractarray.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,11 @@ julia> a
21572157
6.0
21582158
```
21592159
"""
2160-
map!(f::F, dest::AbstractArray, As::AbstractArray...) where {F} = map_n!(f, dest, As)
2160+
function map!(f::F, dest::AbstractArray, As::AbstractArray...) where {F}
2161+
isempty(As) && throw(ArgumentError(
2162+
"""map! requires at least one "source" argument"""))
2163+
map_n!(f, dest, As)
2164+
end
21612165

21622166
map(f) = f()
21632167
map(f, iters...) = collect(Generator(f, iters...))

test/abstractarray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ test_ind2sub(TestAbstractArray)
688688

689689
include("generic_map_tests.jl")
690690
generic_map_tests(map, map!)
691+
@test_throws ArgumentError map!(-, [1])
691692

692693
test_UInt_indexing(TestAbstractArray)
693694
test_13315(TestAbstractArray)

0 commit comments

Comments
 (0)