From ee7d5736d829c438ede76e126513267e2453cbb1 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Mon, 17 Feb 2025 21:21:39 +0000 Subject: [PATCH] Don't return null pointer when asking for the type of a declared global 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. --- src/module.c | 5 +++-- test/core.jl | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/module.c b/src/module.c index ad4613c2d5c56..50d4d90c7f4bb 100644 --- a/src/module.c +++ b/src/module.c @@ -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. diff --git a/test/core.jl b/test/core.jl index 55f3268e61eb5..fd607cc86f1d5 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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