Skip to content

[TypeDeclarationDocblocks] Skip invalid @return tag to fix infinite loop in DocblockReturnArrayFromDirectArrayInstanceRector - #8918

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-9959-docblock-return-invalid-tag
Nov 4, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
fix-9959-docblock-return-invalid-tag

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9959

An invalid docblock like @return array' (trailing quote) parses to an InvalidTagValueNode, so getReturnTagValue() returns null. The rule then falls into the else branch of changeReturnTypeNode(), which keeps adding a fresh @return array<...> tag on every pass while the invalid tag stays in place. The file never reaches a fixed point, so Rector loops until timeout.

Bail out early when the @return tag is invalid, mirroring the existing hasInvalidTag('@return') guard already used in PhpDocTypeChanger::changeReturnType().

Reproducer:

/**
 * @return array'
 */
function test(): array
{
    return ['value'];
}

Added skip_invalid_return_tag.php.inc to cover it.

…ArrayFromDirectArrayInstanceRector to avoid infinite loop
@TomasVotruba
TomasVotruba merged commit e0ed5ec into main Nov 4, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the fix-9959-docblock-return-invalid-tag branch November 4, 2026 08:54
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.

DocblockReturnArrayFromDirectArrayInstanceRector gets caught in an infinite loop

1 participant