Skip to content

Commit bc457f6

Browse files
DilumAluthgeKristofferC
authored andcommitted
Fix deepcopy for Base.GenericCondition (#46406)
(cherry picked from commit 99e8953)
1 parent 5842378 commit bc457f6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

base/deepcopy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function deepcopy_internal(x::GenericCondition, stackdict::IdDict)
140140
if haskey(stackdict, x)
141141
return stackdict[x]
142142
end
143-
y = typeof(x)(deepcopy_internal(x.lock))
143+
y = typeof(x)(deepcopy_internal(x.lock, stackdict))
144144
stackdict[x] = y
145145
return y
146146
end

test/copy.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,19 @@ end
252252
a = [1:3;]
253253
@test copyto!(a, 2:3, 1:1, a, 1:2, 1:1) == [1;1:2;]
254254
end
255+
256+
@testset "`deepcopy` a `GenericCondition`" begin
257+
a = Base.GenericCondition(ReentrantLock())
258+
@test !islocked(a.lock)
259+
lock(a.lock)
260+
@test islocked(a.lock)
261+
b = deepcopy(a)
262+
@test typeof(a) === typeof(b)
263+
@test a != b
264+
@test a !== b
265+
@test typeof(a.lock) === typeof(b.lock)
266+
@test a.lock != b.lock
267+
@test a.lock !== b.lock
268+
@test islocked(a.lock)
269+
@test !islocked(b.lock)
270+
end

0 commit comments

Comments
 (0)