fix(core): foreach value ownership#418
Draft
Guikingone wants to merge 1 commit into
Draft
Conversation
Guikingone
force-pushed
the
fix/405-foreach-value-ownership
branch
from
July 2, 2026 16:16
0c18130 to
4ea3424
Compare
Fixes illegalstudio#405: appending a foreach value into a new array and returning it corrupted the array because the foreach value was always typed as Mixed, forcing array_to_mixed conversion and a type mismatch with the caller's expected element layout. Three changes: 1. foreach_value_type now returns the concrete element type (Str, Int, Bool, Float, Callable) for typed arrays instead of always Mixed. Non-scalar element types (Iterable, Object, etc.) still widen to Mixed. 2. lower_iter_current_value persists the borrowed string slot from an indexed array into an owned heap copy when the result type is Str, so the subsequent release_if_owned does not free the source array's element. For DynamicIterable/Hash paths that always produce a Mixed box, a new unbox_dynamic_iter_current_value_if_needed helper unboxes the Mixed cell into the concrete result type. 3. initialize_foreach_concrete_local_if_needed initializes concrete-typed foreach variables (Str, Int, Bool, Float) to a safe empty value before the first iteration, preventing the first release from reading uninitialized stack memory. Regression tests cover foreach value append with function return, literal array source, inline append, iterating the result, and integer arrays.
Guikingone
force-pushed
the
fix/405-foreach-value-ownership
branch
from
July 4, 2026 17:29
4ea3424 to
edac4e6
Compare
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.
See #405