Skip to content

Commit 305479d

Browse files
authored
Core._eval_import: don't throw away "from" path (#58274)
Fixes accidental variable reuse that caused #58272
2 parents d46b665 + f8faac6 commit 305479d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

base/module.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,14 @@ function _eval_import(imported::Bool, to::Module, from::Union{Expr, Nothing}, pa
107107
elseif path.head !== :.
108108
fail()
109109
end
110-
old_from = from
111-
from, name = eval_import_path(to, from, path, keyword)
110+
m, name = eval_import_path(to, from, path, keyword)
112111

113112
if name !== nothing
114113
asname = asname === nothing ? name : asname
115114
check_macro_rename(name, asname, keyword)
116-
Core._import(to, from, asname, name, imported)
115+
Core._import(to, m, asname, name, imported)
117116
else
118-
Core._import(to, from, asname === nothing ? nameof(from) : asname)
117+
Core._import(to, m, asname === nothing ? nameof(m) : asname)
119118
end
120119
end
121120
end

test/loading.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,3 +1737,15 @@ module M57965
17371737
import Random as R
17381738
end
17391739
@test M57965.R === Base.require(M57965, :Random)
1740+
1741+
# #58272 - _eval_import accidentally reuses evaluated "from" path
1742+
module M58272_1
1743+
const x = 1
1744+
module M58272_2
1745+
const y = 3
1746+
const x = 2
1747+
end
1748+
end
1749+
module M58272_to end
1750+
@eval M58272_to import ..M58272_1: M58272_2.y, x
1751+
@test @eval M58272_to x === 1

0 commit comments

Comments
 (0)