Skip to content

Commit bfe9c2f

Browse files
authored
bpart: Check whether the replaced binding is a type before assuming (#57558)
Somebody may replace the type with an int. Fixes #57515.
1 parent 2e57730 commit bfe9c2f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

base/show.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,10 +1051,13 @@ function check_world_bounded(tn::Core.TypeName)
10511051
isdefined(bnd, :partitions) || return nothing
10521052
partition = @atomic bnd.partitions
10531053
while true
1054-
if is_defined_const_binding(binding_kind(partition)) && partition_restriction(partition) <: tn.wrapper
1055-
max_world = @atomic partition.max_world
1056-
max_world == typemax(UInt) && return nothing
1057-
return Int(partition.min_world):Int(max_world)
1054+
if is_defined_const_binding(binding_kind(partition))
1055+
cval = partition_restriction(partition)
1056+
if isa(cval, Type) && cval <: tn.wrapper
1057+
max_world = @atomic partition.max_world
1058+
max_world == typemax(UInt) && return nothing
1059+
return Int(partition.min_world):Int(max_world)
1060+
end
10581061
end
10591062
isdefined(partition, :next) || return nothing
10601063
partition = @atomic partition.next

test/rebinding.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ module Rebinding
1818
@test Base.binding_kind(@__MODULE__, :Foo) == Base.BINDING_KIND_GUARD
1919
@test contains(repr(x), "@world")
2020

21+
# Test that it still works if Foo is redefined to a non-type
22+
const Foo = 1
23+
24+
@test Base.binding_kind(@__MODULE__, :Foo) == Base.BINDING_KIND_CONST
25+
@test contains(repr(x), "@world")
26+
Base.delete_binding(@__MODULE__, :Foo)
27+
2128
struct Foo
2229
x::Int
2330
end

0 commit comments

Comments
 (0)