Skip to content

Fix InvalidProgramException when NewArray result is ignored - #551

Open
exyi wants to merge 1 commit into
dadhi:masterfrom
exyi:fix-array-ignored-result
Open

Fix InvalidProgramException when NewArray result is ignored#551
exyi wants to merge 1 commit into
dadhi:masterfrom
exyi:fix-array-ignored-result

Conversation

@exyi

@exyi exyi commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This should also fix more subtle problems with i.e. by-reference targets of the array assignment, since NewArray propagated ParentFlags

Fix is to stop propagating parent flags + handle IgnoreResult. Same logic as my fix in 62bde56

Alternative is to propagate IgnoreResult and then don't create the array. However, array creation asserts that integer is positive, so this is invalid optimization, plus the case is quite patological and IMHO not worth optimizing for.

AI use: I let AI generate the tests (before I applied the fix) + for code review of the fix.

var lambda = Lambda<Action>(array);

lambda.CompileSys()();
lambda.CompileFast(true)();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be at least calling of compiled delegates to verify there is no InvalidSomething.. exceptions.
And possibly assert the op codes produced match the expectations.
The same for the test below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did call the compiled delegate, these two tests are two minimized repros of my failed expressions :).

I added the AssertOpCodes call

This should also fix more subtle problems with i.e. by-reference targets
of the array assignment, since NewArray propagated ParentFlags

Fix is to stop propagating parent flags + handle IgnoreResult. Same
logic as my fix in 62bde56

Alternative is to propagate IgnoreResult and then don't create the
array. However, array creation asserts that integer is positive,
so this is invalid optimization, plus the case is quite patological and
IMHO not worth optimizing for.

AI use: I let AI generate the tests (before I applied the fix) + for
code review of the fix.
@exyi
exyi force-pushed the fix-array-ignored-result branch from 6a335ad to 9b28726 Compare August 4, 2026 22:00
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.

2 participants