Skip to content

Add fixtures for arrow functions returning a ?? expression - #8421

Merged
TomasVotruba merged 1 commit into
rectorphp:mainfrom
SanderMuller:add-coalesce-arrow-function-fixtures
Aug 31, 2026
Merged

Add fixtures for arrow functions returning a ?? expression#8421
TomasVotruba merged 1 commit into
rectorphp:mainfrom
SanderMuller:add-coalesce-arrow-function-fixtures

Conversation

@SanderMuller

Copy link
Copy Markdown
Contributor

AddArrowFunctionReturnTypeRector has no fixture where the arrow function body is a ?? expression. On 2.6.4 that case got the type wrong:

fn (int $value) => $value ?? null;
// became
fn (int $value): null => $value ?? null;

Calling that throws a TypeError. Main gets all three cases below right already, so there is no source change here, just the fixtures to keep it that way:

  • nullable param, ?string
  • non-nullable param, int
  • mixed from an untyped array, no type added

On 2.6.4 each one came out as : null.

The rule had no coverage for an arrow function whose body is a null
coalescing expression. On 2.6.4 all three of these cases were typed
`: null`, which is a TypeError for the two that return a value.
@TomasVotruba
TomasVotruba merged commit 054379c into rectorphp:main Aug 31, 2026
44 checks passed
@TomasVotruba

Copy link
Copy Markdown
Member

Thank you 👏

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants