Summary
Refactor StackSlot<T> to eliminate state synchronization issues between Content, Amount, and MaxAmount by introducing a single source of truth and explicit mutation methods.
Motivation
The current implementation:
- Uses mutable property setters for
Content, Amount, and MaxAmount
- Requires cross-property synchronization
- Risks invariant violations such as
Amount not matching actual content
- Contains hidden side effects inside setters
- Allows inconsistent states after public operations
Proposed Change
1. Remove Mutable Setters
Remove public setters and protected fields from:
Amount
MaxAmount
Make them read-only properties.
2. Single Source of Truth
The internal array content must be the only source of truth.
Summary
Refactor
StackSlot<T>to eliminate state synchronization issues betweenContent,Amount, andMaxAmountby introducing a single source of truth and explicit mutation methods.Motivation
The current implementation:
Content,Amount, andMaxAmountAmountnot matching actual contentProposed Change
1. Remove Mutable Setters
Remove public setters and protected fields from:
AmountMaxAmountMake them read-only properties.
2. Single Source of Truth
The internal array
contentmust be the only source of truth.