Skip to content

Conversation

@HDG520
Copy link
Contributor

@HDG520 HDG520 commented Jan 10, 2026

Description

This PR fixes an issue where the parser failed to correctly handle explicit jagged array declarations (e.g., new int[][] { ... }).

Previously, the parser ignored rank specifiers following the base type definition (e.g., the second [] in int[][]), which caused syntax exceptions or incorrect type inference.

Key Changes:

  1. Jagged Array Support: Added logic to NewParser to correctly parse optional trailing rank specifiers (consecutive []).
  2. Parser Combinator Fix: Refactored specific parsing terms to use Terms.Char (soft matching) instead of XsParser.* definitions (hard matching) for starting tokens within OneOf and ZeroOrMany blocks.
    • Reasoning: The existing XsParser definitions include .ElseError(), which throws an immediate exception upon mismatch. This prevented the parser from gracefully backtracking or terminating loops (e.g., distinguishing between a new rank [ and the start of an initializer {).
  3. Type Compatibility: Updated ConstructorType.ArrayInit to allow assignment if the explicit jagged array type is compatible with the inferred element types.

Type of Change

  • Bug fix
  • New feature
  • Documentation

Checklist

  • I have run the existing tests and they pass
  • I have run the existing benchmarks and verified performance has not decreased
  • I have added new tests that prove my change is effective or that my feature works
  • I have added the necessary documentation (if applicable)

varndellwagglebee and others added 4 commits August 18, 2025 08:29
Previously, the parser could not correctly handle explicit jagged array definitions. It ignored rank specifiers after the type name (e.g., the second `[]` in `int[][]`), causing parsing failures or incorrect type inference.

Changes:
- Added logic to parse optional trailing rank specifiers (consecutive `[]`) in `NewParser`.
- Refactored parsing terms to use `Terms.Char` for starting tokens instead of `XsParser.*` definitions. The `XsParser` definitions include `.ElseError()`, which prevented `ZeroOrMany` and `OneOf` combinators from backtracking or terminating loops correctly (e.g., distinguishing between a new rank `[` and the start of an initializer `{`).
- Updated `ConstructorType.ArrayInit` logic to allow assignment if the explicit jagged array type is compatible with the inferred element type.
- Added unit test `Compile_ShouldSucceed_WithExplicitJaggedArraySyntax` to verify support for `new int[][]`.
remove local comments
@HDG520 HDG520 changed the base branch from main to develop January 10, 2026 02:23
@bfarmer67
Copy link
Contributor

Thank you @HDG520. I appreciate you putting this together. I will have a close look at it tomorrow.

@HDG520
Copy link
Contributor Author

HDG520 commented Jan 18, 2026

Thank you @HDG520. I appreciate you putting this together. I will have a close look at it tomorrow.

Great! Actually, this is my first time github contribute code on, so maybe some processes are not well executed, please forgive me😂

@bfarmer67 bfarmer67 merged commit a60f10c into Stillpoint-Software:develop Jan 19, 2026
8 checks passed
@bfarmer67
Copy link
Contributor

Thank you @HDG520. I appreciate you putting this together. I will have a close look at it tomorrow.

Great! Actually, this is my first time github contribute code on, so maybe some processes are not well executed, please forgive me😂

Merged to develop. Thank you. I am in the process of restructuring for net10 and adding multi-targeting. We should have this to main sometime this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants