Skip to content

Commit c585f7e

Browse files
vtjnashKristofferC
authored andcommitted
[REPL] fix type confusion resulting in nonsensical errors (#58414)
(cherry picked from commit a87b056)
1 parent 8feef52 commit c585f7e

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
@@ -445,8 +445,8 @@ function repl_backend_loop(backend::REPLBackend, get_module::Function)
445445
try
446446
ret = f()
447447
put!(backend.response_channel, Pair{Any, Bool}(ret, false))
448-
catch err
449-
put!(backend.response_channel, Pair{Any, Bool}(err, true))
448+
catch
449+
put!(backend.response_channel, Pair{Any, Bool}(current_exceptions(), true))
450450
end
451451
else
452452
ast = ast_or_func
@@ -587,11 +587,11 @@ function print_response(errio::IO, response, backend::Union{REPLBackendRef,Nothi
587587
if val !== nothing && show_value
588588
val2, iserr = if specialdisplay === nothing
589589
# display calls may require being run on the main thread
590-
eval_with_backend(backend) do
590+
call_on_backend(backend) do
591591
Base.invokelatest(display, val)
592592
end
593593
else
594-
eval_with_backend(backend) do
594+
call_on_backend(backend) do
595595
Base.invokelatest(display, specialdisplay, val)
596596
end
597597
end
@@ -708,7 +708,7 @@ function run_frontend(repl::BasicREPL, backend::REPLBackendRef)
708708
(isa(ast,Expr) && ast.head === :incomplete) || break
709709
end
710710
if !isempty(line)
711-
response = eval_with_backend(ast, backend)
711+
response = eval_on_backend(ast, backend)
712712
print_response(repl, response, !ends_with_semicolon(line), false)
713713
end
714714
write(repl.terminal, '\n')
@@ -1153,21 +1153,23 @@ find_hist_file() = get(ENV, "JULIA_HISTORY",
11531153
backend(r::AbstractREPL) = hasproperty(r, :backendref) ? r.backendref : nothing
11541154

11551155

1156-
function eval_with_backend(ast::Expr, backend::REPLBackendRef)
1156+
function eval_on_backend(ast, backend::REPLBackendRef)
11571157
put!(backend.repl_channel, (ast, 1)) # (f, show_value)
11581158
return take!(backend.response_channel) # (val, iserr)
11591159
end
1160-
function eval_with_backend(f, backend::REPLBackendRef)
1160+
function call_on_backend(f, backend::REPLBackendRef)
1161+
applicable(f) || error("internal error: f is not callable")
11611162
put!(backend.repl_channel, (f, 2)) # (f, show_value) 2 indicates function (rather than ast)
11621163
return take!(backend.response_channel) # (val, iserr)
11631164
end
11641165
# if no backend just eval (used by tests)
1165-
function eval_with_backend(f, backend::Nothing)
1166+
eval_on_backend(ast, backend::Nothing) = error("no backend for eval ast")
1167+
function call_on_backend(f, backend::Nothing)
11661168
try
11671169
ret = f()
11681170
return (ret, false) # (val, iserr)
1169-
catch err
1170-
return (err, true)
1171+
catch
1172+
return (current_exceptions(), true)
11711173
end
11721174
end
11731175

@@ -1183,7 +1185,7 @@ function respond(f, repl, main; pass_empty::Bool = false, suppress_on_semicolon:
11831185
local response
11841186
try
11851187
ast = Base.invokelatest(f, line)
1186-
response = eval_with_backend(ast, backend(repl))
1188+
response = eval_on_backend(ast, backend(repl))
11871189
catch
11881190
response = Pair{Any, Bool}(current_exceptions(), true)
11891191
end
@@ -1823,7 +1825,7 @@ function run_frontend(repl::StreamREPL, backend::REPLBackendRef)
18231825
if have_color
18241826
print(repl.stream, Base.color_normal)
18251827
end
1826-
response = eval_with_backend(ast, backend)
1828+
response = eval_on_backend(ast, backend)
18271829
print_response(repl, response, !ends_with_semicolon(line), have_color)
18281830
end
18291831
end

0 commit comments

Comments
 (0)