Skip to content

Commit

Permalink
at-compat for Foo{<:Bar} sugar (#317)
Browse files Browse the repository at this point in the history
* at-compat for Foo{<:Bar} sugar
  • Loading branch information
stevengj authored Feb 5, 2017
1 parent b1098f4 commit 74adb75
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Currently, the `@compat` macro supports the following syntaxes:
includes expressions with lower precedence than `==` you should enclose it in parentheses `x .= (y)` to ensure the
correct order of evaluation.

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

## Type Aliases

* In 0.5, `ASCIIString` and `ByteString` were deprecated, and `UTF8String` was renamed to the (now concrete) type `String`.
Expand Down Expand Up @@ -280,10 +283,14 @@ includes this fix. Find the minimum version from there.
[#17302]: https://github.com/JuliaLang/julia/issues/17302
[#17323]: https://github.com/JuliaLang/julia/issues/17323
[#17510]: https://github.com/JuliaLang/julia/issues/17510
[#17623]: https://github.com/JuliaLang/julia/issues/17623
[#18380]: https://github.com/JuliaLang/julia/issues/18380
[#18484]: https://github.com/JuliaLang/julia/issues/18484
[#18510]: https://github.com/JuliaLang/julia/issues/18510
[#18977]: https://github.com/JuliaLang/julia/issues/18977
[#19088]: https://github.com/JuliaLang/julia/issues/19088
[#19246]: https://github.com/JuliaLang/julia/issues/19246
[#19841]: https://github.com/JuliaLang/julia/issues/19841
[#19950]: https://github.com/JuliaLang/julia/issues/19950
[#20022]: https://github.com/JuliaLang/julia/issues/20022
[#20414]: https://github.com/JuliaLang/julia/issues/20414
6 changes: 5 additions & 1 deletion src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,12 @@ function _compat(ex::Expr)
elseif VERSION < v"0.4.0-dev+5379" && f === :Union
ex = Expr(:call,:Union,ex.args[2:end]...)
elseif ex == :(Ptr{Void})
# Do no change Ptr{Void} to Ptr{Nothing}: 0.4.0-dev+768
# Do not change Ptr{Void} to Ptr{Nothing}: 0.4.0-dev+768
return ex
elseif VERSION < v"0.6.0-dev.2575" #20414
ex = Expr(:curly, map(a -> isexpr(a, :call, 2) && a.args[1] == :(<:) ?
:($TypeVar($(QuoteNode(gensym(:T))), $(a.args[2]), false)) : a,
ex.args)...)
end
elseif ex.head === :macrocall
f = ex.args[1]
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,13 @@ end
@test xor(1,5) == 4
@test 1 5 == 4

# julia#20414
@compat let T = Array{<:Real}, f(x::AbstractVector{<:Real}) = 1
@test isa([3,4],T)
@test !isa([3,4im],T)
@test f(1:3) == f([1,2]) == 1
end

# julia#19246
@test numerator(1//2) === 1
@test denominator(1//2) === 2
Expand Down

0 comments on commit 74adb75

Please sign in to comment.