From 93cc1fc8dc12df7f0a03abff7a7c46f26b9909ba Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Thu, 27 Jul 2017 10:28:47 -0700 Subject: [PATCH] Add fieldcount (#386) --- README.md | 4 ++++ src/Compat.jl | 5 +++++ test/runtests.jl | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/README.md b/README.md index c65c8da8c..6676bdc9b 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,9 @@ Currently, the `@compat` macro supports the following syntaxes: * `logdet` for `Number`s ([#22629]). +* `fieldcount` is equivalent to `nfields` for Julia versions 0.6 and below and is used to + determine the number of fields in a data type ([#22350]). + ## Renamed functions @@ -302,6 +305,7 @@ includes this fix. Find the minimum version from there. [#21346]: https://github.com/JuliaLang/julia/issues/21346 [#22064]: https://github.com/JuliaLang/julia/issues/22064 [#22182]: https://github.com/JuliaLang/julia/issues/22182 +[#22350]: https://github.com/JuliaLang/julia/issues/22350 [#22475]: https://github.com/JuliaLang/julia/issues/22475 [#22633]: https://github.com/JuliaLang/julia/issues/22633 [#22629]: https://github.com/JuliaLang/julia/issues/22629 diff --git a/src/Compat.jl b/src/Compat.jl index c0c82d441..6aaec179c 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -662,6 +662,11 @@ module Sys end end +if VERSION < v"0.7.0-DEV.892" + fieldcount(t) = nfields(t) + export fieldcount +end + include("deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index 45aed189f..ee931d5b1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1917,6 +1917,11 @@ if VERSION < v"0.7.0-DEV.880" end end +# PR 22350 +eval(Expr(:type, false, :TestType, Expr(:block, :(a::Int), :b))) +@test fieldcount(TestType) == 2 +@test fieldcount(Int) == 0 + include("deprecated.jl") nothing