Skip to content

Commit 0163991

Browse files
authored
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.
1 parent 9d2e9ed commit 0163991

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
@@ -8463,3 +8463,11 @@ function f57315()
84638463
return 1
84648464
end
84658465
@test_throws UndefVarError(:flag_2, :local) f57315()
8466+
8467+
# issue #57446
8468+
module GlobalAssign57446
8469+
using Test
8470+
global theglobal
8471+
(@__MODULE__).theglobal = 1
8472+
@test theglobal == 1
8473+
end

0 commit comments

Comments
 (0)