diff --git a/Project.toml b/Project.toml index 7700e37cf..ced2642ae 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ChainRulesCore" uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" -version = "0.9.17" +version = "0.9.18" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/differentials/composite.jl b/src/differentials/composite.jl index 98a56e259..5abbd31dd 100644 --- a/src/differentials/composite.jl +++ b/src/differentials/composite.jl @@ -82,6 +82,11 @@ end Base.keys(comp::Composite) = keys(backing(comp)) Base.propertynames(comp::Composite) = propertynames(backing(comp)) +Base.haskey(comp::Composite, key) = haskey(backing(comp), key) +if isdefined(Base, :hasproperty) + Base.hasproperty(comp::Composite, key::Symbol) = hasproperty(backing(comp), key) +end + Base.iterate(comp::Composite, args...) = iterate(backing(comp), args...) Base.length(comp::Composite) = length(backing(comp)) Base.eltype(::Type{<:Composite{<:Any, T}}) where T = eltype(T) diff --git a/test/differentials/composite.jl b/test/differentials/composite.jl index cb872e9a3..b26ba5c13 100644 --- a/test/differentials/composite.jl +++ b/test/differentials/composite.jl @@ -48,6 +48,10 @@ end @testset "indexing, iterating, and properties" begin @test keys(Composite{Foo}(x=2.5)) == (:x,) @test propertynames(Composite{Foo}(x=2.5)) == (:x,) + @test haskey(Composite{Foo}(x=2.5), :x) == true + if isdefined(Base, :hasproperty) + @test hasproperty(Composite{Foo}(x=2.5), :y) == false + end @test Composite{Foo}(x=2.5).x == 2.5 @test keys(Composite{Tuple{Float64,}}(2.0)) == Base.OneTo(1) @@ -56,6 +60,10 @@ end @test getproperty(Composite{Tuple{Float64,}}(@thunk 2.0^2), 1) == 4.0 @test getproperty(Composite{Tuple{Float64,}}(a=(@thunk 2.0^2),), :a) == 4.0 + # TODO: uncomment this once https://github.com/JuliaLang/julia/issues/35516 + @test_broken haskey(Composite{Tuple{Float64}}(2.0), 1) == true + @test_broken hasproperty(Composite{Tuple{Float64}}(2.0), 2) == false + @test length(Composite{Foo}(x=2.5)) == 1 @test length(Composite{Tuple{Float64,}}(2.0)) == 1