Skip to content

Commit c78016e

Browse files
KenoKristofferC
authored andcommitted
Don't return null pointer when asking for the type of a declared global (#57447)
The `_DECLARED` partition kind used to be considered `guard`, but we now consider it equivalent to an Any-typed `_GLOBAL` (but with weaker redefinition properties). That said, its `->restriction` is NULL, so add it to the list of bindings that should return `nothing` here (and thus `Any` from the bulitin) to fix #57446. (cherry picked from commit 0163991)
1 parent 84c3fd7 commit c78016e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/module.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,10 @@ JL_DLLEXPORT jl_value_t *jl_get_binding_type(jl_module_t *m, jl_sym_t *var)
782782
if (b == NULL)
783783
return jl_nothing;
784784
jl_walk_binding_inplace(&b, &bpart, jl_current_task->world_age);
785-
if (jl_bkind_is_some_guard(jl_binding_kind(bpart)))
785+
enum jl_partition_kind kind = jl_binding_kind(bpart);
786+
if (jl_bkind_is_some_guard(kind) || kind == BINDING_KIND_DECLARED)
786787
return jl_nothing;
787-
if (jl_bkind_is_some_constant(jl_binding_kind(bpart))) {
788+
if (jl_bkind_is_some_constant(kind)) {
788789
// TODO: We would like to return the type of the constant, but
789790
// currently code relies on this returning any to bypass conversion
790791
// before an attempted assignment to a constant.

test/core.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8448,3 +8448,11 @@ myfun57023a(::Type{T}) where {T} = (x = @ccall mycfun()::Ptr{T}; x)
84488448
@test only(code_lowered(myfun57023a)).has_fcall
84498449
myfun57023b(::Type{T}) where {T} = (x = @cfunction myfun57023a Ptr{T} (Ref{T},); x)
84508450
@test only(code_lowered(myfun57023b)).has_fcall
8451+
8452+
# issue #57446
8453+
module GlobalAssign57446
8454+
using Test
8455+
global theglobal
8456+
(@__MODULE__).theglobal = 1
8457+
@test theglobal == 1
8458+
end

0 commit comments

Comments
 (0)