Skip to content

Commit

Permalink
fix deepcopy of QuoteNode and GlobalRef
Browse files Browse the repository at this point in the history
GlobalRefs don't need to be copied, but QuoteNodes do since they can
technically contain mutable data.
  • Loading branch information
JeffBezanson committed Aug 20, 2015
1 parent 4dbab5f commit e0b4510
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/deepcopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

deepcopy(x) = deepcopy_internal(x, ObjectIdDict())

deepcopy_internal(x::Union{Symbol,LambdaStaticData,TopNode,QuoteNode,
deepcopy_internal(x::Union{Symbol,LambdaStaticData,TopNode,GlobalRef,
DataType,Union,Task},
stackdict::ObjectIdDict) = x
deepcopy_internal(x::Tuple, stackdict::ObjectIdDict) =
Expand Down
10 changes: 10 additions & 0 deletions test/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ for (dest, src, bigsrc, emptysrc, res) in [

@test_throws BoundsError copy!(dest, 1, src(), 2, 2)
end

# test behavior of shallow and deep copying
let a = Any[[1]], q = QuoteNode([1])
ca = copy(a); dca = deepcopy(a)
@test ca !== a
@test ca[1] === a[1]
@test dca !== a
@test dca[1] !== a[1]
@test deepcopy(q).value !== q.value
end

0 comments on commit e0b4510

Please sign in to comment.