Skip to content

Commit 74adb75

Browse files
authored
at-compat for Foo{<:Bar} sugar (#317)
* at-compat for Foo{<:Bar} sugar
1 parent b1098f4 commit 74adb75

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ Currently, the `@compat` macro supports the following syntaxes:
6767
includes expressions with lower precedence than `==` you should enclose it in parentheses `x .= (y)` to ensure the
6868
correct order of evaluation.
6969

70+
* `@compat Array{<:Real}` and similar uses of `<:T` to define a set of parameterized types ([#20414]).
71+
In 0.4 and 0.5, this only works for non-nested usages (e.g. you can't define `Array{<:Array{<:Real}}`).
72+
7073
## Type Aliases
7174

7275
* In 0.5, `ASCIIString` and `ByteString` were deprecated, and `UTF8String` was renamed to the (now concrete) type `String`.
@@ -280,10 +283,14 @@ includes this fix. Find the minimum version from there.
280283
[#17302]: https://github.com/JuliaLang/julia/issues/17302
281284
[#17323]: https://github.com/JuliaLang/julia/issues/17323
282285
[#17510]: https://github.com/JuliaLang/julia/issues/17510
286+
[#17623]: https://github.com/JuliaLang/julia/issues/17623
283287
[#18380]: https://github.com/JuliaLang/julia/issues/18380
284288
[#18484]: https://github.com/JuliaLang/julia/issues/18484
285289
[#18510]: https://github.com/JuliaLang/julia/issues/18510
286290
[#18977]: https://github.com/JuliaLang/julia/issues/18977
287291
[#19088]: https://github.com/JuliaLang/julia/issues/19088
288292
[#19246]: https://github.com/JuliaLang/julia/issues/19246
293+
[#19841]: https://github.com/JuliaLang/julia/issues/19841
289294
[#19950]: https://github.com/JuliaLang/julia/issues/19950
295+
[#20022]: https://github.com/JuliaLang/julia/issues/20022
296+
[#20414]: https://github.com/JuliaLang/julia/issues/20414

src/Compat.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,12 @@ function _compat(ex::Expr)
638638
elseif VERSION < v"0.4.0-dev+5379" && f === :Union
639639
ex = Expr(:call,:Union,ex.args[2:end]...)
640640
elseif ex == :(Ptr{Void})
641-
# Do no change Ptr{Void} to Ptr{Nothing}: 0.4.0-dev+768
641+
# Do not change Ptr{Void} to Ptr{Nothing}: 0.4.0-dev+768
642642
return ex
643+
elseif VERSION < v"0.6.0-dev.2575" #20414
644+
ex = Expr(:curly, map(a -> isexpr(a, :call, 2) && a.args[1] == :(<:) ?
645+
:($TypeVar($(QuoteNode(gensym(:T))), $(a.args[2]), false)) : a,
646+
ex.args)...)
643647
end
644648
elseif ex.head === :macrocall
645649
f = ex.args[1]

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,13 @@ end
15321532
@test xor(1,5) == 4
15331533
@test 1 5 == 4
15341534

1535+
# julia#20414
1536+
@compat let T = Array{<:Real}, f(x::AbstractVector{<:Real}) = 1
1537+
@test isa([3,4],T)
1538+
@test !isa([3,4im],T)
1539+
@test f(1:3) == f([1,2]) == 1
1540+
end
1541+
15351542
# julia#19246
15361543
@test numerator(1//2) === 1
15371544
@test denominator(1//2) === 2

0 commit comments

Comments
 (0)