From eeec432a9172813d9224dd6fa14f5797f6fdea5c Mon Sep 17 00:00:00 2001 From: Paul Berg Date: Sat, 2 Apr 2022 11:39:38 +0200 Subject: [PATCH] Fix implicit binding import for aliased bindings (#44827) `b->name` is used to lookup in `b->owner`, not `var`. (cherry picked from commit dbe41d44ec8677232cbf8faddf97a66d8d901647) --- src/module.c | 2 +- test/syntax.jl | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/module.c b/src/module.c index e3b333bd142a5..1efaceef6112c 100644 --- a/src/module.c +++ b/src/module.c @@ -328,7 +328,7 @@ static jl_binding_t *jl_get_binding_(jl_module_t *m, jl_sym_t *var, modstack_t * // do a full import to prevent the result of this lookup // from changing, for example if this var is assigned to // later. - module_import_(m, b->owner, var, var, 0); + module_import_(m, b->owner, b->name, var, 0); return b; } return NULL; diff --git a/test/syntax.jl b/test/syntax.jl index 0bc6c5f8a538d..2c393af22a2cf 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -2490,7 +2490,10 @@ end module Mod2 import ..Mod.x as x_from_mod +import ..Mod.x as x_from_mod2 const y = 2 + +export x_from_mod2 end import .Mod: x as x2 @@ -2535,6 +2538,12 @@ import .Mod2.x_from_mod @test @isdefined(x_from_mod) @test x_from_mod == Mod.x + +using .Mod2 + +@test_nowarn @eval x_from_mod2 +@test @isdefined(x_from_mod2) +@test x_from_mod2 == x_from_mod == Mod.x end import .TestImportAs.Mod2 as M2