Skip to content

Commit a87b056

Browse files
authored
[REPL] fix type confusion resulting in nonsensical errors (#58414)
1 parent 7df60f4 commit a87b056

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
@@ -452,8 +452,8 @@ function repl_backend_loop(backend::REPLBackend, get_module::Function)
452452
try
453453
ret = f()
454454
put!(backend.response_channel, Pair{Any, Bool}(ret, false))
455-
catch err
456-
put!(backend.response_channel, Pair{Any, Bool}(err, true))
455+
catch
456+
put!(backend.response_channel, Pair{Any, Bool}(current_exceptions(), true))
457457
end
458458
else
459459
ast = ast_or_func
@@ -594,11 +594,11 @@ function print_response(errio::IO, response, backend::Union{REPLBackendRef,Nothi
594594
if val !== nothing && show_value
595595
val2, iserr = if specialdisplay === nothing
596596
# display calls may require being run on the main thread
597-
eval_with_backend(backend) do
597+
call_on_backend(backend) do
598598
Base.invokelatest(display, val)
599599
end
600600
else
601-
eval_with_backend(backend) do
601+
call_on_backend(backend) do
602602
Base.invokelatest(display, specialdisplay, val)
603603
end
604604
end
@@ -715,7 +715,7 @@ function run_frontend(repl::BasicREPL, backend::REPLBackendRef)
715715
(isa(ast,Expr) && ast.head === :incomplete) || break
716716
end
717717
if !isempty(line)
718-
response = eval_with_backend(ast, backend)
718+
response = eval_on_backend(ast, backend)
719719
print_response(repl, response, !ends_with_semicolon(line), false)
720720
end
721721
write(repl.terminal, '\n')
@@ -1166,21 +1166,23 @@ find_hist_file() = get(ENV, "JULIA_HISTORY",
11661166
backend(r::AbstractREPL) = hasproperty(r, :backendref) ? r.backendref : nothing
11671167

11681168

1169-
function eval_with_backend(ast::Expr, backend::REPLBackendRef)
1169+
function eval_on_backend(ast, backend::REPLBackendRef)
11701170
put!(backend.repl_channel, (ast, 1)) # (f, show_value)
11711171
return take!(backend.response_channel) # (val, iserr)
11721172
end
1173-
function eval_with_backend(f, backend::REPLBackendRef)
1173+
function call_on_backend(f, backend::REPLBackendRef)
1174+
applicable(f) || error("internal error: f is not callable")
11741175
put!(backend.repl_channel, (f, 2)) # (f, show_value) 2 indicates function (rather than ast)
11751176
return take!(backend.response_channel) # (val, iserr)
11761177
end
11771178
# if no backend just eval (used by tests)
1178-
function eval_with_backend(f, backend::Nothing)
1179+
eval_on_backend(ast, backend::Nothing) = error("no backend for eval ast")
1180+
function call_on_backend(f, backend::Nothing)
11791181
try
11801182
ret = f()
11811183
return (ret, false) # (val, iserr)
1182-
catch err
1183-
return (err, true)
1184+
catch
1185+
return (current_exceptions(), true)
11841186
end
11851187
end
11861188

@@ -1196,7 +1198,7 @@ function respond(f, repl, main; pass_empty::Bool = false, suppress_on_semicolon:
11961198
local response
11971199
try
11981200
ast = Base.invokelatest(f, line)
1199-
response = eval_with_backend(ast, backend(repl))
1201+
response = eval_on_backend(ast, backend(repl))
12001202
catch
12011203
response = Pair{Any, Bool}(current_exceptions(), true)
12021204
end
@@ -1803,7 +1805,7 @@ function run_frontend(repl::StreamREPL, backend::REPLBackendRef)
18031805
if have_color
18041806
print(repl.stream, Base.color_normal)
18051807
end
1806-
response = eval_with_backend(ast, backend)
1808+
response = eval_on_backend(ast, backend)
18071809
print_response(repl, response, !ends_with_semicolon(line), have_color)
18081810
end
18091811
end

0 commit comments

Comments
 (0)