Skip to content

Fix a panic on a field write through a slice element - #42

Merged
nnutter merged 1 commit into
masterfrom
skill-laser-semi
Nov 5, 2026
Merged

nnutter merged 1 commit into
masterfrom
skill-laser-semi

Conversation

@nnutter

@nnutter nnutter commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

No description provided.

The nonmutating analyzer stopped the whole run with exit status 2 on a
field write whose container was not an identifier. `containerStorageVisible`
accepted only an identifier and panicked on every other expression, and
`visibleMutationOrigin` called it for the container of each selector
write. These shapes crashed:

    //constable:nonmutating
    func F(s []E) { s[0].N = 1 }        // *ast.IndexExpr
    //constable:nonmutating
    func G(p *E) { (*p).N = 1 }         // *ast.StarExpr
    //constable:nonmutating
    func H(ss [][]E) { ss[0][0].N = 1 } // nested *ast.IndexExpr

A selector's container lives in caller-visible memory exactly when the
container expression does, so `exprRefersToCallerVisibleMemory` subsumes
`containerStorageVisible` for an identifier and answers for the other
shapes without a panic. Delete the narrower function and call the general
one at both sites.

`rootOrigin` finds the parameter or receiver that starts a chain, so a
write below an index or a dereference reports the identifier that the
caller passed. The same change removes two silent misses that the old
container check produced: `o.inner.data[0] = 0` on a value receiver now
reports, and so does `(*p).inner.data[0] = 0` on a pointer parameter.

Add regression cases for the three crashing shapes and for the value
receiver chain, which passed silently before. Keep `o.inner = Inner{}` as
a control: a field write on the receiver copy must stay unreported.

Change-Id: Iade884a097fb704a54fc026e0c9d245f54989fdc
@nnutter
nnutter added this pull request to stack #44 November 5, 2026 08:59
@nnutter nnutter changed the title Fix a panic on a field write through a non-identifier Fix a panic on a field write through a slice element Nov 5, 2026
@nnutter
nnutter merged commit 2d363e9 into master Nov 5, 2026
5 of 6 checks passed
@nnutter
nnutter deleted the skill-laser-semi branch November 5, 2026 16:46
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