Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1406,12 +1406,24 @@ function repl_eval_counter(hp)
end

function out_transform(@nospecialize(x), n::Ref{Int})
return quote
return Expr(:toplevel, get_usings!([], x)..., quote
let __temp_val_a72df459 = $x
$capture_result($n, __temp_val_a72df459)
__temp_val_a72df459
end
end)
end

function get_usings!(usings, ex)
# get all `using` and `import` statements which are at the top level
for (i, arg) in enumerate(ex.args)
if Base.isexpr(arg, :toplevel)
get_usings!(usings, arg)
elseif Base.isexpr(arg, [:using, :import])
push!(usings, popat!(ex.args, i))
end
end
return usings
end

function capture_result(n::Ref{Int}, @nospecialize(x))
Expand Down
5 changes: 5 additions & 0 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,11 @@ fake_repl() do stdin_write, stdout_read, repl
s = sendrepl2("x_47878 = range(-1; stop = 1)\n", "-1:1")
@test contains(s, "Out[11]: -1:1")

# Test for https://github.com/JuliaLang/julia/issues/49041
s = sendrepl2("using Test; @test true", "In [14]")
@test !contains(s, "ERROR")
@test contains(s, "Test Passed")

write(stdin_write, '\x04')
Base.wait(repltask)
end