From bc457f682ce517c38fa31df48d8d3c13dccd221b Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Mon, 22 Aug 2022 10:34:14 -0400 Subject: [PATCH] Fix `deepcopy` for `Base.GenericCondition` (#46406) (cherry picked from commit 99e8953c0fcb626d643207650381f1e3fbff76e2) --- base/deepcopy.jl | 2 +- test/copy.jl | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/base/deepcopy.jl b/base/deepcopy.jl index 317d999004c42..74c9d2b49c123 100644 --- a/base/deepcopy.jl +++ b/base/deepcopy.jl @@ -140,7 +140,7 @@ function deepcopy_internal(x::GenericCondition, stackdict::IdDict) if haskey(stackdict, x) return stackdict[x] end - y = typeof(x)(deepcopy_internal(x.lock)) + y = typeof(x)(deepcopy_internal(x.lock, stackdict)) stackdict[x] = y return y end diff --git a/test/copy.jl b/test/copy.jl index c4fcff40f2b3f..633beee5f2af3 100644 --- a/test/copy.jl +++ b/test/copy.jl @@ -252,3 +252,19 @@ end a = [1:3;] @test copyto!(a, 2:3, 1:1, a, 1:2, 1:1) == [1;1:2;] end + +@testset "`deepcopy` a `GenericCondition`" begin + a = Base.GenericCondition(ReentrantLock()) + @test !islocked(a.lock) + lock(a.lock) + @test islocked(a.lock) + b = deepcopy(a) + @test typeof(a) === typeof(b) + @test a != b + @test a !== b + @test typeof(a.lock) === typeof(b.lock) + @test a.lock != b.lock + @test a.lock !== b.lock + @test islocked(a.lock) + @test !islocked(b.lock) +end