diff --git a/base/task.jl b/base/task.jl index fe64a0b0d6458..1985fc03b9611 100644 --- a/base/task.jl +++ b/base/task.jl @@ -457,12 +457,12 @@ true """ function schedule(t::Task, @nospecialize(arg); error=false) # schedule a task to be (re)started with the given value or exception - t.state == :runnable || error("schedule: Task not runnable") + t.state == :runnable || Base.error("schedule: Task not runnable") if error t.queue === nothing || Base.list_deletefirst!(t.queue, t) t.exception = arg else - t.queue === nothing || error("schedule: Task not runnable") + t.queue === nothing || Base.error("schedule: Task not runnable") t.result = arg end enq_work(t) diff --git a/test/channels.jl b/test/channels.jl index a01c1d98972a5..ae787f71c9bed 100644 --- a/test/channels.jl +++ b/test/channels.jl @@ -389,3 +389,9 @@ let a = Ref(0) GC.gc() @test a[] == 1 end + +# trying to `schedule` a finished task +let t = @async nothing + wait(t) + @test_throws ErrorException("schedule: Task not runnable") schedule(t, nothing) +end