Skip to content

Commit

Permalink
Add atsign-compat support for CartesianRange
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Jul 13, 2017
1 parent c3e15e9 commit 676654d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Compat.collect(A)` returns an `Array`, no matter what indices the array `A` has (Julia 0.5 and higher). [#21257]

* `@compat foo(::CartesianRange{N})` to replace the former
`foo(::CartesianRange{CartesianIndex{N}})` ([#20974]). Note that
`CartesianRange` now has two type parameters, so using them as
fields in other `struct`s requires manual intervention.

## Module Aliases

* In 0.6, some 0.5 iterator functions have been moved to the `Base.Iterators`
Expand Down Expand Up @@ -377,6 +382,7 @@ includes this fix. Find the minimum version from there.
[#20414]: https://github.com/JuliaLang/julia/issues/20414
[#20418]: https://github.com/JuliaLang/julia/issues/20418
[#20500]: https://github.com/JuliaLang/julia/issues/20500
[#20974]: https://github.com/JuliaLang/julia/issues/20974
[#21257]: https://github.com/JuliaLang/julia/issues/21257
[#21346]: https://github.com/JuliaLang/julia/issues/21346
[#22064]: https://github.com/JuliaLang/julia/issues/22064
8 changes: 8 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,14 @@ function _compat(ex::Expr)
end
end
end
if VERSION < v"0.7.0-DEV.880"
if ex.head == :curly && ex.args[1] == :CartesianRange && length(ex.args) >= 2
a = ex.args[2]
if a != :CartesianIndex && !(isa(a, Expr) && a.head == :curly && a.args[1] == :CartesianIndex)
return Expr(:curly, :CartesianRange, Expr(:curly, :CartesianIndex, ex.args[2]))
end
end
end
return Expr(ex.head, map(_compat, ex.args)...)
end
function _compat(ex::Symbol)
Expand Down
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,20 @@ let
@test_throws MethodError Dates.Month(1) < Dates.Day(1)
end

let
@compat cr(::CartesianRange{2}) = 2
@test cr(CartesianRange(1:5, 2:4)) == 2
@test_throws MethodError cr(CartesianRange(1:5, 2:4, -1:1))
end
if VERSION < v"0.7.0-DEV.880"
# ensure we don't bork any non-updated expressions
let
@compat cr(::CartesianRange{CartesianIndex{2}}) = 2
@test cr(CartesianRange(1:5, 2:4)) == 2
@test_throws MethodError cr(CartesianRange(1:5, 2:4, -1:1))
end
end

include("to-be-deprecated.jl")

nothing

0 comments on commit 676654d

Please sign in to comment.