Skip to content

Commit 0aac5db

Browse files
vtjnashKristoffer Carlsson
authored andcommitted
[REPL] fix type confusion resulting in nonsensical errors (#58414)
(cherry picked from commit a87b056)
1 parent bb6dc83 commit 0aac5db

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

stdlib/REPL/src/REPL.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ function repl_backend_loop(backend::REPLBackend, get_module::Function)
360360
try
361361
ret = f()
362362
put!(backend.response_channel, Pair{Any, Bool}(ret, false))
363-
catch err
364-
put!(backend.response_channel, Pair{Any, Bool}(err, true))
363+
catch
364+
put!(backend.response_channel, Pair{Any, Bool}(current_exceptions(), true))
365365
end
366366
else
367367
ast = ast_or_func
@@ -433,11 +433,11 @@ function print_response(errio::IO, response, backend::Union{REPLBackendRef,Nothi
433433
if val !== nothing && show_value
434434
val2, iserr = if specialdisplay === nothing
435435
# display calls may require being run on the main thread
436-
eval_with_backend(backend) do
436+
call_on_backend(backend) do
437437
Base.invokelatest(display, val)
438438
end
439439
else
440-
eval_with_backend(backend) do
440+
call_on_backend(backend) do
441441
Base.invokelatest(display, specialdisplay, val)
442442
end
443443
end
@@ -554,7 +554,7 @@ function run_frontend(repl::BasicREPL, backend::REPLBackendRef)
554554
(isa(ast,Expr) && ast.head === :incomplete) || break
555555
end
556556
if !isempty(line)
557-
response = eval_with_backend(ast, backend)
557+
response = eval_on_backend(ast, backend)
558558
print_response(repl, response, !ends_with_semicolon(line), false)
559559
end
560560
write(repl.terminal, '\n')
@@ -997,21 +997,23 @@ find_hist_file() = get(ENV, "JULIA_HISTORY",
997997
backend(r::AbstractREPL) = hasproperty(r, :backendref) ? r.backendref : nothing
998998

999999

1000-
function eval_with_backend(ast::Expr, backend::REPLBackendRef)
1000+
function eval_on_backend(ast, backend::REPLBackendRef)
10011001
put!(backend.repl_channel, (ast, 1)) # (f, show_value)
10021002
return take!(backend.response_channel) # (val, iserr)
10031003
end
1004-
function eval_with_backend(f, backend::REPLBackendRef)
1004+
function call_on_backend(f, backend::REPLBackendRef)
1005+
applicable(f) || error("internal error: f is not callable")
10051006
put!(backend.repl_channel, (f, 2)) # (f, show_value) 2 indicates function (rather than ast)
10061007
return take!(backend.response_channel) # (val, iserr)
10071008
end
10081009
# if no backend just eval (used by tests)
1009-
function eval_with_backend(f, backend::Nothing)
1010+
eval_on_backend(ast, backend::Nothing) = error("no backend for eval ast")
1011+
function call_on_backend(f, backend::Nothing)
10101012
try
10111013
ret = f()
10121014
return (ret, false) # (val, iserr)
1013-
catch err
1014-
return (err, true)
1015+
catch
1016+
return (current_exceptions(), true)
10151017
end
10161018
end
10171019

@@ -1027,7 +1029,7 @@ function respond(f, repl, main; pass_empty::Bool = false, suppress_on_semicolon:
10271029
local response
10281030
try
10291031
ast = Base.invokelatest(f, line)
1030-
response = eval_with_backend(ast, backend(repl))
1032+
response = eval_on_backend(ast, backend(repl))
10311033
catch
10321034
response = Pair{Any, Bool}(current_exceptions(), true)
10331035
end
@@ -1667,7 +1669,7 @@ function run_frontend(repl::StreamREPL, backend::REPLBackendRef)
16671669
if have_color
16681670
print(repl.stream, Base.color_normal)
16691671
end
1670-
response = eval_with_backend(ast, backend)
1672+
response = eval_on_backend(ast, backend)
16711673
print_response(repl, response, !ends_with_semicolon(line), have_color)
16721674
end
16731675
end

0 commit comments

Comments
 (0)