Skip to content

Commit

Permalink
Add Compat for TypeUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Feb 2, 2017
1 parent 586d784 commit e98b9a2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit e98b9a2

Please sign in to comment.