Skip to content

Commit 676654d

Browse files
committed
Add atsign-compat support for CartesianRange
1 parent c3e15e9 commit 676654d

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ Currently, the `@compat` macro supports the following syntaxes:
8383

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

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

8893
* In 0.6, some 0.5 iterator functions have been moved to the `Base.Iterators`
@@ -377,6 +382,7 @@ includes this fix. Find the minimum version from there.
377382
[#20414]: https://github.com/JuliaLang/julia/issues/20414
378383
[#20418]: https://github.com/JuliaLang/julia/issues/20418
379384
[#20500]: https://github.com/JuliaLang/julia/issues/20500
385+
[#20974]: https://github.com/JuliaLang/julia/issues/20974
380386
[#21257]: https://github.com/JuliaLang/julia/issues/21257
381387
[#21346]: https://github.com/JuliaLang/julia/issues/21346
382388
[#22064]: https://github.com/JuliaLang/julia/issues/22064

src/Compat.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,14 @@ function _compat(ex::Expr)
483483
end
484484
end
485485
end
486+
if VERSION < v"0.7.0-DEV.880"
487+
if ex.head == :curly && ex.args[1] == :CartesianRange && length(ex.args) >= 2
488+
a = ex.args[2]
489+
if a != :CartesianIndex && !(isa(a, Expr) && a.head == :curly && a.args[1] == :CartesianIndex)
490+
return Expr(:curly, :CartesianRange, Expr(:curly, :CartesianIndex, ex.args[2]))
491+
end
492+
end
493+
end
486494
return Expr(ex.head, map(_compat, ex.args)...)
487495
end
488496
function _compat(ex::Symbol)

test/runtests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,20 @@ let
18931893
@test_throws MethodError Dates.Month(1) < Dates.Day(1)
18941894
end
18951895

1896+
let
1897+
@compat cr(::CartesianRange{2}) = 2
1898+
@test cr(CartesianRange(1:5, 2:4)) == 2
1899+
@test_throws MethodError cr(CartesianRange(1:5, 2:4, -1:1))
1900+
end
1901+
if VERSION < v"0.7.0-DEV.880"
1902+
# ensure we don't bork any non-updated expressions
1903+
let
1904+
@compat cr(::CartesianRange{CartesianIndex{2}}) = 2
1905+
@test cr(CartesianRange(1:5, 2:4)) == 2
1906+
@test_throws MethodError cr(CartesianRange(1:5, 2:4, -1:1))
1907+
end
1908+
end
1909+
18961910
include("to-be-deprecated.jl")
18971911

18981912
nothing

0 commit comments

Comments
 (0)