Skip to content

Commit

Permalink
Fix incorrect use of isimmutable (#33042)
Browse files Browse the repository at this point in the history
This function operates on values not on types (though it is a bit of
a trap). Also add a test to catch this bug.
  • Loading branch information
Keno authored Aug 23, 2019
1 parent 5ae63b8 commit aee3fc2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/gcutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ end

function finalizer(f::Ptr{Cvoid}, o::T) where T
@_inline_meta
if isimmutable(T)
error("objects of type ", T, " cannot be finalized")
if isimmutable(o)
error("objects of type ", typeof(o), " cannot be finalized")
end
ccall(:jl_gc_add_ptr_finalizer, Cvoid, (Ptr{Cvoid}, Any, Ptr{Cvoid}),
Core.getptls(), o, f)
Expand Down
4 changes: 4 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,3 +747,7 @@ end

# Pointer 0-arg constructor
@test Ptr{Cvoid}() == C_NULL

# Finalizer with immutable should throw
@test_throws ErrorException finalizer(x->nothing, 1)
@test_throws ErrorException finalizer(C_NULL, 1)

0 comments on commit aee3fc2

Please sign in to comment.