Skip to content

Commit 4fc7f69

Browse files
committed
in Channel put!, convert value to Channel type
`put!(ch::Channel{T}, v)` should convert `v` to type `T`. This can prevent errors like: ``` julia> c = Channel{Int}(0) Channel{Int64}(sz_max:0,sz_curr:0) julia> @async put!(c, :a) Task (runnable) @0x00007ff5b9d79270 julia> isready(c) && take!(c) ERROR: TypeError: in take_unbuffered, in typeassert, expected Int64, got Symbol Stacktrace: [1] take_unbuffered(::Channel{Int64}) at ./channels.jl:323 [2] take!(::Channel{Int64}) at ./channels.jl:306 [3] top-level scope at none:0 ```
1 parent bb7d043 commit 4fc7f69

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

base/channels.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,10 @@ Append an item `v` to the channel `c`. Blocks if the channel is full.
246246
For unbuffered channels, blocks until a [`take!`](@ref) is performed by a different
247247
task.
248248
"""
249-
function put!(c::Channel, v)
249+
function put!(c::Channel{T}, v) where T
250250
check_channel_state(c)
251-
isbuffered(c) ? put_buffered(c,v) : put_unbuffered(c,v)
251+
vT = convert(T, v)
252+
isbuffered(c) ? put_buffered(c,vT) : put_unbuffered(c,vT)
252253
end
253254

254255
function put_buffered(c::Channel, v)

0 commit comments

Comments
 (0)