Skip to content

Fix fold return type annotations - #82

Merged
GrahamCampbell merged 1 commit into
masterfrom
fold-return-types
Aug 23, 2026
Merged

Fix fold return type annotations#82
GrahamCampbell merged 1 commit into
masterfrom
fold-return-types

Conversation

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

The foldLeft and foldRight annotations used a single template for the initial value and the callback result, which rejects valid heterogeneous folds, as @axlon pointed out in #77. That fix went too far the other way, though, since None returns the initial value at runtime, so the true return type is the union of the two. This types the base methods as returning S|R and adds exact overriding docblocks on Some and None, which removes the false positives without blessing any code that could fail at runtime, and leaves our own PHPStan run clean with no baseline changes.

@GrahamCampbell
GrahamCampbell merged commit 5a6de7b into master Aug 23, 2026
21 of 22 checks passed
@GrahamCampbell
GrahamCampbell deleted the fold-return-types branch August 23, 2026 22:18
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.

1 participant