Skip to content

Commit aee3fc2

Browse files
authored
Fix incorrect use of isimmutable (#33042)
This function operates on values not on types (though it is a bit of a trap). Also add a test to catch this bug.
1 parent 5ae63b8 commit aee3fc2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

base/gcutils.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ end
2626

2727
function finalizer(f::Ptr{Cvoid}, o::T) where T
2828
@_inline_meta
29-
if isimmutable(T)
30-
error("objects of type ", T, " cannot be finalized")
29+
if isimmutable(o)
30+
error("objects of type ", typeof(o), " cannot be finalized")
3131
end
3232
ccall(:jl_gc_add_ptr_finalizer, Cvoid, (Ptr{Cvoid}, Any, Ptr{Cvoid}),
3333
Core.getptls(), o, f)

test/misc.jl

+4
Original file line numberDiff line numberDiff line change
@@ -747,3 +747,7 @@ end
747747

748748
# Pointer 0-arg constructor
749749
@test Ptr{Cvoid}() == C_NULL
750+
751+
# Finalizer with immutable should throw
752+
@test_throws ErrorException finalizer(x->nothing, 1)
753+
@test_throws ErrorException finalizer(C_NULL, 1)

0 commit comments

Comments
 (0)