Fix array initializer type casting and multidimensional array initialization - #110
Merged
Merged
Conversation
…t support - Add EmitCast in DoEmitStructureAssignment to cast each element to the array's element type (fixes #39: float-to-int array init) - Add recursive EmitArrayStructuredInit for nested StructureExpression items to support multidimensional array initialization (fixes #46) - Fix ArrayElementExpression.DoEmit to skip LoadPointer when element type is CArrayType (array-to-pointer decay for multidimensional reads) - Add tests for float/double-to-int, int-to-float, and 2D array init Agent-Logs-Url: https://github.com/praeclarum/CLanguage/sessions/b190017e-c781-4532-ba81-cb23a4dcacda Co-authored-by: praeclarum <323548+praeclarum@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix array initializer with float values producing incorrect int values
Fix array initializer type casting and multidimensional array initialization
Mar 31, 2026
praeclarum
marked this pull request as ready for review
March 31, 2026 20:32
praeclarum
approved these changes
Mar 31, 2026
Closed
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.
int arr[2] = {2.0f, 3.0f}silently produces zeroes becauseDoEmitStructureAssignmentemits initializer values without casting to the target element type. Multidimensional array init (int a[2][3] = {{1,2,3},{4,5,6}}) also fails because the read path unconditionally dereferences element pointers even when the element is itself an array.Changes
AssignExpression.cs— AddEmitCastfrom each item's type to the array element type. Extract recursiveEmitArrayStructuredInitto walk nestedStructureExpressionnodes for multidimensional arrays.ArrayElementExpression.cs— SkipLoadPointerwhen the evaluated element type isCArrayType(array-to-pointer decay instead of value load).ArrayTests.cs— Tests for float→int, double→int, int→float array init, and 2D array init (global + local).