diff --git a/README.md b/README.md index 96dafd15e..c5f9c9b77 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `Compat.isapprox` with `nans` keyword argument [#20022](https://github.com/JuliaLang/julia/pull/20022) +* 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 diff --git a/src/Compat.jl b/src/Compat.jl index 5ebfb6941..0ca3f92af 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1770,4 +1770,14 @@ else import Base.isapprox end -end # module +module TypeUtils + @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 diff --git a/test/runtests.jl b/test/runtests.jl index 20a0e950f..b24f72d14 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1603,3 +1603,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)