Skip to content

Commit 05c07e1

Browse files
authored
[REPL] Do not corrupt input when using numbered_prompt! mode (#59730)
Fix the unbounded possible corruption of the user input by reverting to a non-scoped begin instead of let. ```julia julia> ex = Base.remove_linenums!(:(using A; using B; using C)); REPL.Numbered.get_usings!([], ex) 2-element Vector{Any}: :(using A) :(using C) julia> ex quote using B end ```
1 parent 6e697c3 commit 05c07e1

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

stdlib/REPL/src/REPL.jl

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,25 +1845,10 @@ function repl_eval_counter(hp)
18451845
end
18461846

18471847
function out_transform(@nospecialize(x), n::Ref{Int})
1848-
return Expr(:toplevel, get_usings!([], x)..., quote
1849-
let __temp_val_a72df459 = $x
1850-
$capture_result($n, __temp_val_a72df459)
1851-
__temp_val_a72df459
1852-
end
1853-
end)
1854-
end
1855-
1856-
function get_usings!(usings, ex)
1857-
ex isa Expr || return usings
1858-
# get all `using` and `import` statements which are at the top level
1859-
for (i, arg) in enumerate(ex.args)
1860-
if Base.isexpr(arg, :toplevel)
1861-
get_usings!(usings, arg)
1862-
elseif Base.isexpr(arg, [:using, :import])
1863-
push!(usings, popat!(ex.args, i))
1864-
end
1865-
end
1866-
return usings
1848+
return Expr(:block, # avoid line numbers or scope that would leak into the output and change the meaning of x
1849+
:(local __temp_val_a72df459 = $x),
1850+
Expr(:call, capture_result, n, :__temp_val_a72df459),
1851+
:__temp_val_a72df459)
18671852
end
18681853

18691854
function create_global_out!(mod)

0 commit comments

Comments
 (0)