Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `take!` method for `Task`s since some functions now return `Channel`s instead of `Task`s [#19841](https://github.com/JuliaLang/julia/pull/19841).

* The `isabstract`, `parameter_upper_bound`, `typename` reflection methods were added in Julia 0.6. This package re-exports these from the `Compat.TypeUtils` submodule. On earlier versions of julia, that module contains the same functions, but operating on the pre-0.6 type system representation.

## Renamed functions

* `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively
Expand Down
13 changes: 12 additions & 1 deletion src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1773,4 +1773,15 @@ else
import Base.isapprox
end

end # module
module TypeUtils
using ..Compat: @static
@static if isdefined(Core, :UnionAll)
using Base: isabstract, parameter_upper_bound, typename
else
isabstract(t::DataType) = t.abstract
parameter_upper_bound(t::DataType, idx) = t.parameters[idx].ub
typename(t::DataType) = t.name
end
export isabstract, parameter_upper_bound, typename
end # module TypeUtils
end # module Compat
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1604,3 +1604,11 @@ end
# julia#20022
@test !Compat.isapprox(NaN, NaN)
@test Compat.isapprox(NaN, NaN, nans=true)

# julia#20006
abstract AbstractFoo20006
immutable ConcreteFoo20006{T<:Int} <: AbstractFoo20006
end
@test Compat.TypeUtils.isabstract(AbstractFoo20006)
@test Compat.TypeUtils.parameter_upper_bound(ConcreteFoo20006, 1) == Int
@test isa(Compat.TypeUtils.typename(Array), TypeName)