File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -101,14 +101,18 @@ end
101101
102102Add an element to the back and overwrite front if full.
103103"""
104- @inline function Base. push! (cb:: CircularBuffer , data)
104+ @inline function Base. push! (cb:: CircularBuffer{T} , data) where T
105+
106+ # As per the behaviour of Base.push!
107+ data_converted = convert (T, data)
108+
105109 # if full, increment and overwrite, otherwise push
106110 if cb. length == cb. capacity
107111 cb. first = (cb. first == cb. capacity ? 1 : cb. first + 1 )
108112 else
109113 cb. length += 1
110114 end
111- @inbounds cb. buffer[_buffer_index (cb, cb. length)] = data
115+ @inbounds cb. buffer[_buffer_index (cb, cb. length)] = data_converted
112116 return cb
113117end
114118
Original file line number Diff line number Diff line change 165165 end
166166 end
167167
168+ @testset " Issue 754" begin
169+ cb = CircularBuffer {Int} (5 )
170+ @test size (cb) == (0 ,)
171+ @test_throws InexactError push! (cb, 1.5 )
172+ @test size (cb) == (0 ,)
173+ push! (cb, 1.0 )
174+ @test size (cb) == (1 ,)
175+ end
176+
168177 @testset " resize!" begin
169178 @testset " resize an empty buffer" begin
170179 cb = CircularBuffer {Int} (3 )
You can’t perform that action at this time.
0 commit comments