Skip to content

Commit d12d6fb

Browse files
committed
Merge pull request #110 from JuliaLang/kms/curly_vector_array
at-compat for Vector{T}(), Vector{T}(n), Array{T} (fixes #105)
2 parents aec96b7 + 03cdc64 commit d12d6fb

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Currently, the `@compat` macro supports the following syntaxes:
5050

5151
* `@compat f(t::Timer)` - mimic the Julia 0.4 Timer class
5252

53+
* `@compat Vector{Int}()`, `@compat Vector{UInt8}(n)`, `@compat Array{Float32}(2,2)` - Julia 0.4-style array constructors.
54+
5355
## Type Aliases
5456

5557
* `typealias AbstractString String` - `String` has been renamed to `AbstractString` [#8872](https://github.com/JuliaLang/julia/pull/8872)

src/Compat.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ function _compat(ex::Expr)
279279
if isexpr(s, :curly) && s.args[1] == :Val
280280
ex = Expr(:call, :chol, ex.args[2], s.args[2])
281281
end
282+
elseif VERSION < v"0.4.0-dev+4739" && isexpr(f, :curly) && (f.args[1] == :Vector || f.args[1] == :Array)
283+
if f.args[1] == :Vector && length(ex.args) == 1
284+
ex = Expr(:call, :Array, f.args[2], 0)
285+
else
286+
ex = Expr(:call, :Array, f.args[2], ex.args[2:end]...)
287+
end
282288
end
283289
elseif ex.head == :curly
284290
f = ex.args[1]

test/runtests.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,26 @@ Compat.@irrational mathconst_one 1.0 big(1.)
367367
# gc_enable(::Bool)
368368
@test gc_enable(false)
369369
@test !gc_enable(true)
370+
371+
# Vector{Int}(), Array{Int}
372+
373+
@test @compat typeof(Vector{Int}()) == Array{Int,1}
374+
@test @compat length(Vector{Int}()) == 0
375+
376+
@test @compat typeof(Vector{Int8}(10)) == Array{Int8,1}
377+
@test @compat length(Vector{Int8}(10)) == 10
378+
379+
@test @compat typeof(Array{UInt16}()) == Array{UInt16,0}
380+
@test @compat length(Array{UInt16}()) == 1
381+
382+
@test @compat typeof(Array{UInt16}(0)) == Array{UInt16,1}
383+
@test @compat length(Array{UInt16}(0)) == 0
384+
385+
@test @compat typeof(Array{Float16}(5)) == Array{Float16,1}
386+
@test @compat length(Array{Float16}(5)) == 5
387+
388+
@test @compat typeof(Array{String}(2,2)) == Array{String,2}
389+
@test @compat size(Array{String}(2,2)) == (2,2)
390+
391+
@test @compat typeof(Array{Rational{Int}}(2,2,2,2,2)) == Array{Rational{Int},5}
392+
@test @compat size(Array{Rational{Int}}(2,2,2,2,2)) == (2,2,2,2,2)

0 commit comments

Comments
 (0)