Skip to content

Commit 0f275e3

Browse files
authored
bindings: Define behavior of using an ambiguous binding (JuliaLang#60804)
We were missing handling for the case where the binding that we're using is ambiguous. There are two possible behaviors: 1. The ambiguous binding gets ignored for the purpose of resolution 2. The ambiguity poisons and the imported binding is also ambiguous Current behavior between these two depends on resolution order (which is bad and part of what the assert was complaining about). This decides that case #2 is the correct behavior and fixes JuliaLang#60659.
1 parent e1dda38 commit 0f275e3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/module.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ static void update_implicit_resolution(struct implicit_search_resolution *to_upd
106106
return;
107107
}
108108
if (to_update->ultimate_kind == PARTITION_KIND_GUARD) {
109-
assert(resolution.binding_or_const);
110109
to_update->ultimate_kind = resolution.ultimate_kind;
111110
to_update->binding_or_const = resolution.binding_or_const;
112111
to_update->debug_only_import_from = resolution.debug_only_import_from;
@@ -329,6 +328,10 @@ struct implicit_search_resolution jl_resolve_implicit_import(jl_binding_t *b, mo
329328
imp_resolution.binding_or_const = tempbpart->restriction;
330329
imp_resolution.debug_only_ultimate_binding = tempb;
331330
imp_resolution.ultimate_kind = PARTITION_KIND_IMPLICIT_CONST;
331+
} else if (kind == PARTITION_KIND_FAILED) {
332+
imp_resolution.binding_or_const = NULL;
333+
imp_resolution.debug_only_ultimate_binding = tempb;
334+
imp_resolution.ultimate_kind = PARTITION_KIND_FAILED;
332335
}
333336
}
334337
// If this using has the reexport flag, mark that the binding should be reexported

test/core.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8687,3 +8687,17 @@ primitive type ByteString58434 (18 * 8) end
86878687

86888688
@test Base.datatype_isbitsegal(Tuple{ByteString58434}) == false
86898689
@test Base.datatype_haspadding(Tuple{ByteString58434}) == (length(Base.padding(Tuple{ByteString58434})) > 0)
8690+
8691+
# #60659 - Behavior of using'd ambiguous bindings
8692+
module AmbiguousUsing60659
8693+
using Test
8694+
module A
8695+
export X
8696+
module B; struct X; end; export X; end
8697+
module C; struct X; end; export X; end
8698+
using .B, .C
8699+
end
8700+
module D; struct X; end; export X; end
8701+
using .D, .A
8702+
@test_throws UndefVarError X
8703+
end

0 commit comments

Comments
 (0)