Skip to content

Commit 7744985

Browse files
authored
fix JuliaLang#27546 by using jl_set_global instead of eval to set Main.ans (JuliaLang#27562)
1 parent 404e0fe commit 7744985

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

base/client.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function eval_user_input(@nospecialize(ast), show_value::Bool)
121121
else
122122
ast = Meta.lower(Main, ast)
123123
value = Core.eval(Main, ast)
124-
Core.eval(Main, Expr(:body, Expr(:(=), :ans, QuoteNode(value)), Expr(:return, nothing)))
124+
ccall(:jl_set_global, Cvoid, (Any, Any, Any), Main, :ans, value)
125125
if !(value === nothing) && show_value
126126
if have_color
127127
print(answer_color())

stdlib/REPL/src/REPL.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function eval_user_input(@nospecialize(ast), backend::REPLBackend)
8585
value = Core.eval(Main, ast)
8686
backend.in_eval = false
8787
# note: value wrapped carefully here to ensure it doesn't get passed through expand
88-
Core.eval(Main, Expr(:body, Expr(:(=), :ans, QuoteNode(value)), Expr(:return, nothing)))
88+
ccall(:jl_set_global, Cvoid, (Any, Any, Any), Main, :ans, value)
8989
put!(backend.response_channel, (value, nothing))
9090
end
9191
break

stdlib/REPL/test/repl.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,3 +961,19 @@ for (line, expr) in Pair[
961961
buf = IOBuffer()
962962
@test Base.eval(REPL._helpmode(buf, line)) isa Union{Markdown.MD,Nothing}
963963
end
964+
965+
# PR #27562
966+
fake_repl() do stdin_write, stdout_read, repl
967+
repltask = @async begin
968+
REPL.run_repl(repl)
969+
end
970+
write(stdin_write, "Expr(:call, GlobalRef(Base.Math, :float), Core.SlotNumber(1))\n")
971+
readline(stdout_read)
972+
@test readline(stdout_read) == "\e[0m:((Base.Math.float)(_1))"
973+
write(stdin_write, "ans\n")
974+
readline(stdout_read)
975+
readline(stdout_read)
976+
@test readline(stdout_read) == "\e[0m:((Base.Math.float)(_1))"
977+
write(stdin_write, '\x04')
978+
Base._wait(repltask)
979+
end

0 commit comments

Comments
 (0)