Skip to content

Commit

Permalink
Fixed #3684: redefine Channel#pretty_print to avoid using uninitializ…
Browse files Browse the repository at this point in the history
…ed variable
  • Loading branch information
asterite committed Dec 13, 2016
1 parent 9634fc4 commit 9d2deee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spec/std/channel_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,14 @@ describe Channel::Buffered do
ch = Channel::Buffered(Int32).new(10)
ch.inspect.should eq("#<Channel::Buffered(Int32):0x#{ch.object_id.to_s(16)}>")
end

it "does pretty_inspect on unbuffered channel" do
ch = Channel::Unbuffered(Int32).new
ch.pretty_inspect.should eq("#<Channel::Unbuffered(Int32):0x#{ch.object_id.to_s(16)}>")
end

it "does pretty_inspect on buffered channel" do
ch = Channel::Buffered(Int32).new(10)
ch.pretty_inspect.should eq("#<Channel::Buffered(Int32):0x#{ch.object_id.to_s(16)}>")
end
end
4 changes: 4 additions & 0 deletions src/concurrent/channel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ abstract class Channel(T)
to_s(io)
end

def pretty_print(pp)
pp.text inspect
end

def wait_for_receive
@receivers << Fiber.current
end
Expand Down

0 comments on commit 9d2deee

Please sign in to comment.