Skip to content

Commit

Permalink
deprecate unintended methods of zeros, ones (#21183)
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3126 authored and timholy committed Apr 4, 2017
1 parent e796e39 commit 18e864b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 12 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,18 @@ end
end
end

# #19635
for fname in (:ones, :zeros)
@eval @deprecate ($fname)(T::Type, arr) ($fname)(T, size(arr))
@eval ($fname)(T::Type, i::Integer) = ($fname)(T, (i,))
@eval function ($fname){T}(::Type{T}, arr::Array{T})
msg = string("`", $fname, "{T}(::Type{T}, arr::Array{T})` is deprecated, use ",
"`", $fname , "(T, size(arr))` instead. ",
)
error(msg)
end
end

# END 0.6 deprecations

# BEGIN 1.0 deprecations
Expand Down
11 changes: 5 additions & 6 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2054,12 +2054,11 @@ end
zs = zeros(SparseMatrixCSC([1 2; 3 4]), Complex{Float64}, (2,3))
test_zeros(zs, SparseMatrixCSC{Complex{Float64}}, (2, 3))

@testset "#19265" begin
@test_throws MethodError zeros(Float64, [1.])
x = [1.]
test_zeros(zeros(x, Float64), Vector{Float64}, (1,))
@test x == [1.]
end
# #19265"
@test_throws ErrorException zeros(Float64, [1.]) # TODO change to MethodError, when v0.6 deprecations are done
x = [1.]
test_zeros(zeros(x, Float64), Vector{Float64}, (1,))
@test x == [1.]

# exotic indexing
oarr = zeros(randn(3), UInt16, 1:3, -1:0)
Expand Down

0 comments on commit 18e864b

Please sign in to comment.