Skip to content

Commit a371899

Browse files
authored
bpart: Ignore guard bindings for ambiguity purposes (#57406)
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.
1 parent 0c5372f commit a371899

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/module.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void jl_check_new_binding_implicit(
6565

6666
jl_binding_t *deprecated_impb = NULL;
6767
jl_binding_t *impb = NULL;
68+
jl_binding_partition_t *impbpart = NULL;
6869

6970
size_t min_world = new_bpart->min_world;
7071
size_t max_world = jl_atomic_load_relaxed(&new_bpart->max_world);
@@ -111,6 +112,14 @@ void jl_check_new_binding_implicit(
111112
if (impb) {
112113
if (tempb->deprecated)
113114
continue;
115+
if (jl_binding_kind(tempbpart) == BINDING_KIND_GUARD &&
116+
jl_binding_kind(impbpart) != BINDING_KIND_GUARD)
117+
continue;
118+
if (jl_binding_kind(impbpart) == BINDING_KIND_GUARD) {
119+
impb = tempb;
120+
impbpart = tempbpart;
121+
continue;
122+
}
114123
if (eq_bindings(tempbpart, impb, world))
115124
continue;
116125
// Binding is ambiguous
@@ -132,6 +141,7 @@ void jl_check_new_binding_implicit(
132141
}
133142
else {
134143
impb = tempb;
144+
impbpart = tempbpart;
135145
}
136146
}
137147
}

test/syntax.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4088,3 +4088,17 @@ abstract type A57267{S, T} end
40884088
B57267{S} = A57267{S, 1}
40894089
const C57267 = B57267
40904090
end
4091+
4092+
# #57404 - Binding ambiguity resolution ignores guard bindings
4093+
module Ambig57404
4094+
module A
4095+
export S
4096+
end
4097+
using .A
4098+
module B
4099+
const S = 1
4100+
export S
4101+
end
4102+
using .B
4103+
end
4104+
@test Ambig57404.S == 1

0 commit comments

Comments
 (0)