Skip to content

Commit dd546fc

Browse files
StoneCypherclaude
andcommitted
Fix three bugs: pop() return type, fill() cursor reset, and comment errors
This commit addresses three bugs found in the circular buffer implementation: 1. Type Safety Bug - pop() return type (HIGH severity) - Changed pop() return type from 'T | undefined' to 'T' - The method never returns undefined; it either returns T or throws RangeError - Previous type signature was misleading and could cause incorrect null checks - Affects: src/ts/circular_buffer.ts:708 2. Consistency Bug - fill() missing cursor reset (MEDIUM severity) - Added 'this._cursor = 0' to fill() method - Now consistent with similar buffer-reorganizing methods (reverse, every, some) - Previously left internal rotation state unnormalized after filling - Affects: src/ts/circular_buffer.ts:501 3. Documentation Bug - copy-paste comment errors (LOW severity) - Fixed comment in some() that incorrectly said "every can mutate" - Fixed typo "_this.offset" → "this._offset" - Comments were copied from every() method and not updated - Affects: src/ts/circular_buffer.ts:611, 616 All tests pass (84/84) with 100% coverage maintained. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent d246f7f commit dd546fc

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

package-lock.json

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ts/circular_buffer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ class circular_buffer<T> {
498498
}
499499

500500
this._length = this._capacity;
501+
this._cursor = 0;
501502

502503
return this._values;
503504

@@ -607,12 +608,12 @@ class circular_buffer<T> {
607608
const normalized = this.toArray(),
608609
res = normalized.some(functor, thisArg);
609610

610-
// every can mutate, so, store the result, which will usually be nothing
611+
// some can mutate, so, store the result, which will usually be nothing
611612

612613
this._values = normalized;
613614
this._values.length = this._capacity; // stack with new empties
614615
this._cursor = 0; // accomodate internal rotation
615-
// do not mutate _this.offset; it doesn't change
616+
// do not mutate this._offset; it doesn't change
616617

617618
return res;
618619

@@ -705,7 +706,7 @@ class circular_buffer<T> {
705706
*
706707
*/
707708

708-
pop(): T | undefined {
709+
pop(): T {
709710

710711
if (this._length <= 0) {
711712
throw new RangeError(`Cannot pop, structure is empty`);

0 commit comments

Comments
 (0)