Skip to content

Commit

Permalink
deprecate zero-arg Matrix constructors (#14201)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Jan 30, 2017
1 parent 40eda99 commit 5855520
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ typealias NTuple{N,T} Tuple{Vararg{T,N}}
(::Type{Array{T}}){T}(m::Int, n::Int, o::Int) = Array{T,3}(m, n, o)

(::Type{Array{T,1}}){T}() = Array{T,1}(0)
(::Type{Array{T,2}}){T}() = Array{T,2}(0, 0)

# primitive Symbol constructors
function Symbol(s::String)
Expand Down
11 changes: 11 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1849,4 +1849,15 @@ end)

@deprecate FloatRange{T}(start::T, step, len, den) Base.floatrange(T, start, step, len, den)

@noinline zero_arg_matrix_constructor(prefix::String) =
depwarn("$prefix() is deprecated, use $prefix(0, 0) instead.", :zero_arg_matrix_constructor)
function (::Type{Matrix{T}}){T}()
zero_arg_matrix_constructor("Matrix{T}")
return Matrix{T}(0, 0)
end
function (::Type{Matrix})()
zero_arg_matrix_constructor("Matrix")
return Matrix(0, 0)
end

# End deprecations scheduled for 0.6
1 change: 0 additions & 1 deletion base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ include("subarray.jl")
(::Type{Vector})() = Array{Any,1}(0)
(::Type{Vector{T}}){T}(m::Integer) = Array{T,1}(Int(m))
(::Type{Vector})(m::Integer) = Array{Any,1}(Int(m))
(::Type{Matrix})() = Array{Any,2}(0, 0)
(::Type{Matrix{T}}){T}(m::Integer, n::Integer) = Matrix{T}(Int(m), Int(n))
(::Type{Matrix})(m::Integer, n::Integer) = Matrix{Any}(Int(m), Int(n))

Expand Down
10 changes: 5 additions & 5 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ end
@test convert(Array{Int}, a) == a
@test convert(Array{Float64}, a) == a
@test convert(Matrix, a) == a
@test convert(Matrix{Int}, a) == a
@test convert(Matrix{Float64}, a) == a
b = Base.ReshapedArray(1:3, (3,), ())
@test convert(Array, b) == b
Expand Down Expand Up @@ -271,18 +270,19 @@ end
@test typeof(Vector(3)) == Vector{Any}
@test typeof(Vector()) == Vector{Any}
@test typeof(Matrix{Int}(2,3)) == Matrix{Int}
@test typeof(Matrix{Int}()) == Matrix{Int}
@test typeof(Matrix(2,3)) == Matrix{Any}
@test typeof(Matrix()) == Matrix{Any}

@test size(Vector{Int}(3)) == (3,)
@test size(Vector{Int}()) == (0,)
@test size(Vector(3)) == (3,)
@test size(Vector()) == (0,)
@test size(Matrix{Int}(2,3)) == (2,3)
@test size(Matrix{Int}()) == (0,0)
@test size(Matrix(2,3)) == (2,3)
@test size(Matrix()) == (0,0)

@test_throws MethodError Array{Int,3}()
# TODO: will throw MethodError after 0.6 deprecations are deleted
@test_throws ErrorException Matrix{Int}()
@test_throws ErrorException Matrix()
end
@testset "get" begin
A = reshape(1:24, 3, 8)
Expand Down

0 comments on commit 5855520

Please sign in to comment.