Skip to content

Commit

Permalink
Fix replinit after jn/world
Browse files Browse the repository at this point in the history
The callback needs to be run in the latest world.

Also use `showerror` instead of `show` to display the error.
  • Loading branch information
yuyichao committed Dec 28, 2016
1 parent 8ef3daa commit 233278a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,17 @@ file.
"""
atreplinit(f::Function) = (unshift!(repl_hooks, f); nothing)

function _atreplinit(repl)
function __atreplinit(repl)
for f in repl_hooks
try
f(repl)
catch err
show(STDERR, err)
showerror(STDERR, err)
println(STDERR)
end
end
end
_atreplinit(repl) = eval(Main, :($__atreplinit($repl)))

function _start()
empty!(ARGS)
Expand Down
16 changes: 16 additions & 0 deletions test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,19 @@ let io = IOBuffer()
end, [])
@test length(String(take!(io))) < 1500
end

function test_replinit()
stdin_write, stdout_read, stdout_read, repl = fake_repl()
# Relies on implementation detail to make sure we only have the single
# replinit callback we want to test.
saved_replinit = copy(Base.repl_hooks)
slot = Ref(false)
# Create a closure from a newer world to check if `_atreplinit`
# can run it correctly
atreplinit(eval(:(repl::Base.REPL.LineEditREPL->($slot[] = true))))
Base._atreplinit(repl)
@test slot[]
@test_throws MethodError Base.repl_hooks[1](repl)
copy!(Base.repl_hooks, saved_replinit)
end
test_replinit()

0 comments on commit 233278a

Please sign in to comment.