Skip to content

Fix prepend! of a SentinelVector to itself - #138

Open
quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/sentinelvector-prepend-self
Open

quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/sentinelvector-prepend-self

Conversation

@quinnj-bot

@quinnj-bot quinnj-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Why

A SentinelVector should give the same answers as a Vector{Union{T, Missing}} with the same values. prepend!(x, x) grew x first and then read the new, uninitialized front slots as the items to prepend. It returned leftover memory for bits types and threw UndefRefError for String:

julia> x = SentinelArray([1, 2]); prepend!(x, x)
4-element SentinelVector{Int64, Int64, Missing, Vector{Int64}}:
          1
 6130790401     # Vector gives 2; the value is whatever was in memory
          1
          2

julia> x = SentinelArray(["a", "b"], "NA", missing); prepend!(x, x)
ERROR: UndefRefError: access to undefined reference

What changed

  • prepend!(x, items::AbstractVector) passes Base.unalias(x, items), so it copies items first when it is x or a view of x.

Scope

  • append! was already correct for this case.

Blast radius

Calls where items does not share storage with x pay one identity check.

Verification

🤖 Generated with Claude Code

quinnj and others added 2 commits November 18, 2026 23:04
Fails on main; passes with the next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_prepend! grows the vector before reading the items, so prepend!(x, x)
read the new uninitialized slots. Pass Base.unalias(x, items) so an
aliased source is copied first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant