Skip to content

fix(typechecker): validate arrays.reduce callback return type matches accumulator (#2241) - #2251

Merged
SchoolyB merged 1 commit into
bugfixes/august-5-2026from
fix/issue-2241
Aug 2, 2026
Merged

fix(typechecker): validate arrays.reduce callback return type matches accumulator (#2241)#2251
SchoolyB merged 1 commit into
bugfixes/august-5-2026from
fix/issue-2241

Conversation

@SchoolyB

@SchoolyB SchoolyB commented Aug 2, 2026

Copy link
Copy Markdown
Member

Fixes #2241

arrays.reduce() was missing validation that the reducer callback's return type matches the accumulator type. When a callback returned a different type (e.g., string instead of int), the typechecker accepted it and codegen produced code that reinterpreted the return value's bits as the accumulator type, resulting in garbage data at runtime.

Added an else if branch in the existing reduce callback validation (E9004) that resolves the initial value's type and compares it against the callback's return type, emitting E9004 on mismatch.

Added fail test E9004_arrays_reduce_wrong_return.gray.

@github-actions github-actions Bot added typechecker Related to type checking and validation tests Related to unit tests or test infrastructure grayc Related to the grayscale compiler core or its internal tooling labels Aug 2, 2026
@SchoolyB
SchoolyB changed the base branch from main to bugfixes/august-5-2026 August 2, 2026 19:48
@SchoolyB
SchoolyB merged commit ef4ca05 into bugfixes/august-5-2026 Aug 2, 2026
4 of 6 checks passed
@SchoolyB
SchoolyB deleted the fix/issue-2241 branch August 2, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

grayc Related to the grayscale compiler core or its internal tooling tests Related to unit tests or test infrastructure typechecker Related to type checking and validation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: arrays.reduce does not validate callback return type, produces garbage on type mismatch

1 participant