Add subscript setter support with handler and call count#337
Merged
sidepelican merged 2 commits intouber:masterfrom Mar 3, 2026
Merged
Add subscript setter support with handler and call count#337sidepelican merged 2 commits intouber:masterfrom
sidepelican merged 2 commits intouber:masterfrom
Conversation
…cking Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
sidepelican
approved these changes
Mar 3, 2026
Collaborator
sidepelican
left a comment
There was a problem hiding this comment.
Nice catch. Thank you!
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.
Summary
SetCallCountandSetHandlerinstead of the previous emptyset { }stub{ get }and{ get set }subscripts correctly; get-only subscripts now omit the setter entirelySendableand actor mocks) using the sameMockoloMutex/MockoloHandlerStatepattern as getter handlingDesign decisions
No built-in value store for setters
The generated setter handler receives all subscript parameters plus
newValue, but it does not persist values automatically.A generic built-in store is hard to make sound:
HashableAny-erased storage would lose type safetyInstead, storage can be added explicitly in tests when needed:
This keeps the generated code minimal and leaves storage semantics under the test author's control.
Current limitation
Protocol refinement is not reconciled across inheritance. If a parent protocol declares a
{ get set }subscript and a child narrows it to{ get }, the generated mock follows the accessor block on the protocol being mocked rather than merging inherited accessor requirements.Behavioral changes
Previously, all subscripts, including
{ get }-only subscripts, were generated with an emptyset { }block. That made get-only mocks writable and diverged from the protocol contract.Now:
{ get }subscripts generate only a getter{ get set }subscripts generate a functional setter withSetCallCountandSetHandlerThe main compatibility impact is that code which wrote to a get-only mock subscript will now fail to compile, which is the correct behavior.