Conversation
.zi-load-object ended with
___retval+=$?
return __retval
`__retval' is assigned nowhere. Zsh evaluates a bare name in `return'
arithmetically and an unset parameter is 0, so the helper always reported
success:
zsh -fc 'f(){ local ___retval=3; return __retval; }; f; print $?' -> 0
zsh -fc 'f(){ local ___retval=3; return ___retval; }; f; print $?' -> 3
The two sibling returns a few lines away use the correct three-underscore name.
The sole caller already does the right thing: it stores the result in
___last_retval, adds it to ___retval once, and gates turbo scheduling on
`0 == ___last_retval'. All of that was defeated by the constant 0, so a failed
immediate load counted as success and turbo scheduling still went ahead.
Fixing only the return would have double-counted, because the helper also added
to the caller's dynamically scoped ___retval. Give the helper its own local
result, return that, and drop the accumulation so the caller owns it, which is
the contract the caller was already written for.
tests/load-object-status.zsh stubs .zi-load and .zi-load-snippet, so the status
under test is unambiguously the one supplied. It covers plugin and snippet on
both the success and failure paths, and pins that the helper leaves the caller's
___retval alone. Against the unfixed helper it reports `plugin failure: expected
7, got 0'.
Closes #446
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
.zi-load-objectalways reported success. Every immediate load looked like it worked.The defect
__retvalis assigned nowhere in the file. Zsh evaluates a bare name inreturnarithmetically, and an unset parameter is0:The two sibling returns a few lines away use the correct three-underscore name, so this is a single missing underscore.
Why it mattered
The sole caller was already written correctly:
It captures the result, accumulates it once, and gates turbo scheduling on it. A constant
0defeated all three: a failed immediate load was counted as success, and turbo scheduling proceeded anyway.The trap in fixing it
Returning the real status while leaving
___retval+=$?in place would have double-counted every failure, because the helper was also adding to the caller's dynamically scoped accumulator. The fix separates the two: the helper gets its own local result and returns it, and the accumulation is dropped so the caller owns it, which is the contract the caller already assumed.Test
tests/load-object-status.zshstubs.zi-loadand.zi-load-snippetso the status under test is unambiguously the one supplied, with no dependency on a real plug-in, the network, or the filesystem. It covers plugin and snippet across success and failure, and pins that the helper leaves the caller's$___retvaluntouched.Observed against the unfixed helper:
Registered in
zsh-n.yml(both path filters and a job), since that workflow enumerates tests explicitly and an unregistered file never runs.Full suite 19/19,
zsh -nclean.This is item 1 of the Wave 1 list in
docs/maintainers/core-architecture-audit.md, preserved on thedocs/core-architecture-auditbranch.Closes #446