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