Skip to content

Commit 3fa1167

Browse files
committed
Add atsign-compat support for CartesianRange
1 parent bdf61d8 commit 3fa1167

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ Currently, the `@compat` macro supports the following syntaxes:
7575

7676
* `Compat.collect(A)` returns an `Array`, no matter what indices the array `A` has. [#21257]
7777

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

8085
* In 0.6, some 0.5 iterator functions have been moved to the `Base.Iterators`
@@ -280,6 +285,7 @@ includes this fix. Find the minimum version from there.
280285
[#20414]: https://github.com/JuliaLang/julia/issues/20414
281286
[#20418]: https://github.com/JuliaLang/julia/issues/20418
282287
[#20500]: https://github.com/JuliaLang/julia/issues/20500
288+
[#20974]: https://github.com/JuliaLang/julia/issues/20974
283289
[#21257]: https://github.com/JuliaLang/julia/issues/21257
284290
[#21346]: https://github.com/JuliaLang/julia/issues/21346
285291
[#22064]: https://github.com/JuliaLang/julia/issues/22064

src/Compat.jl

+8
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ function _compat(ex::Expr)
178178
end
179179
end
180180
end
181+
if VERSION < v"0.7.0-DEV.880"
182+
if ex.head == :curly && ex.args[1] == :CartesianRange && length(ex.args) >= 2
183+
a = ex.args[2]
184+
if a != :CartesianIndex && !(isa(a, Expr) && a.head == :curly && a.args[1] == :CartesianIndex)
185+
return Expr(:curly, :CartesianRange, Expr(:curly, :CartesianIndex, ex.args[2]))
186+
end
187+
end
188+
end
181189
return Expr(ex.head, map(_compat, ex.args)...)
182190
end
183191

test/runtests.jl

+14
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,20 @@ let
18681868
@test_throws MethodError Dates.Month(1) < Dates.Day(1)
18691869
end
18701870

1871+
let
1872+
@compat cr(::CartesianRange{2}) = 2
1873+
@test cr(CartesianRange((5, 3))) == 2
1874+
@test_throws MethodError cr(CartesianRange((5, 3, 2)))
1875+
end
1876+
if VERSION < v"0.7.0-DEV.880"
1877+
# ensure we don't bork any non-updated expressions
1878+
let
1879+
@compat cr(::CartesianRange{CartesianIndex{2}}) = 2
1880+
@test cr(CartesianRange((5, 3))) == 2
1881+
@test_throws MethodError cr(CartesianRange((5, 3, 2)))
1882+
end
1883+
end
1884+
18711885
include("deprecated.jl")
18721886

18731887
nothing

0 commit comments

Comments
 (0)