Skip to content

Commit

Permalink
bpart: Ignore guard bindings for ambiguity purposes (#57406)
Browse files Browse the repository at this point in the history
This makes non-guard bindings stronger than guard bindings for ambiguity
purposes. Note that both of these are yet stronger than deprecated
bindings, so if there's a "non-guard deprecated" binding and a "guard
non-deprecated" binding, the latter will win and the access will be
UndefVarError. I think this is the closest to the 1.11 behavior without
relying on resolvedness.

Fixes #57404

This PR is against #57405 just because that PR touches the common
interface, but is conceptually independent.

(cherry picked from commit a371899)
  • Loading branch information
Keno authored and KristofferC committed Feb 15, 2025
1 parent 41e0464 commit 423cb56
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void jl_check_new_binding_implicit(

jl_binding_t *deprecated_impb = NULL;
jl_binding_t *impb = NULL;
jl_binding_partition_t *impbpart = NULL;

size_t min_world = new_bpart->min_world;
size_t max_world = jl_atomic_load_relaxed(&new_bpart->max_world);
Expand Down Expand Up @@ -111,6 +112,14 @@ void jl_check_new_binding_implicit(
if (impb) {
if (tempb->deprecated)
continue;
if (jl_binding_kind(tempbpart) == BINDING_KIND_GUARD &&
jl_binding_kind(impbpart) != BINDING_KIND_GUARD)
continue;
if (jl_binding_kind(impbpart) == BINDING_KIND_GUARD) {
impb = tempb;
impbpart = tempbpart;
continue;
}
if (eq_bindings(tempbpart, impb, world))
continue;
// Binding is ambiguous
Expand All @@ -132,6 +141,7 @@ void jl_check_new_binding_implicit(
}
else {
impb = tempb;
impbpart = tempbpart;
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4089,3 +4089,17 @@ abstract type A57267{S, T} end
B57267{S} = A57267{S, 1}
const C57267 = B57267
end

# #57404 - Binding ambiguity resolution ignores guard bindings
module Ambig57404
module A
export S
end
using .A
module B
const S = 1
export S
end
using .B
end
@test Ambig57404.S == 1

0 comments on commit 423cb56

Please sign in to comment.