Skip to content

Commit

Permalink
Don't return null pointer when asking for the type of a declared global
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Keno committed Feb 17, 2025
1 parent e331deb commit ee7d573
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,10 @@ JL_DLLEXPORT jl_value_t *jl_get_binding_type(jl_module_t *m, jl_sym_t *var)
if (b == NULL)
return jl_nothing;
jl_walk_binding_inplace(&b, &bpart, jl_current_task->world_age);
if (jl_bkind_is_some_guard(jl_binding_kind(bpart)))
enum jl_partition_kind kind = jl_binding_kind(bpart);
if (jl_bkind_is_some_guard(kind) || kind == BINDING_KIND_DECLARED)
return jl_nothing;
if (jl_bkind_is_some_constant(jl_binding_kind(bpart))) {
if (jl_bkind_is_some_constant(kind)) {
// TODO: We would like to return the type of the constant, but
// currently code relies on this returning any to bypass conversion
// before an attempted assignment to a constant.
Expand Down
8 changes: 8 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8463,3 +8463,11 @@ function f57315()
return 1
end
@test_throws UndefVarError(:flag_2, :local) f57315()

# issue #57446
module GlobalAssign57446
using Test
global theglobal
(@__MODULE__).theglobal = 1
@test theglobal == 1
end

0 comments on commit ee7d573

Please sign in to comment.