Skip to content

Commit b93cd6c

Browse files
phpstan-botclaude
authored andcommitted
Cover the preg_replace_callback arrow-function reproducer in ArrowFunctionReturnTypeRuleTest
The second playground link on phpstan/phpstan#14914 uses an arrow function without an explicit return type as the preg_replace_callback callback. That case goes through ArrowFunctionReturnTypeRule (not ClosureReturnTypeRule), so add it to bug-14914.php and assert no error there. Without the replaceInFunctionCallStackParameterType fix it reports "Anonymous function should return 'aa' but returns 'aa'|'possible?'". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 8183e68 commit b93cd6c

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,9 @@ public function testBugFunctionMethodConstants(): void
7777
$this->analyse([__DIR__ . '/data/bug-anonymous-function-method-constant.php'], []);
7878
}
7979

80+
public function testBug14914(): void
81+
{
82+
$this->analyse([__DIR__ . '/data/bug-14914.php'], []);
83+
}
84+
8085
}

tests/PHPStan/Rules/Functions/data/bug-14914.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@ function (array $match): string {
1818
flags: PREG_UNMATCHED_AS_NULL,
1919
);
2020
}
21+
22+
function doBar(): void
23+
{
24+
preg_replace_callback(
25+
'/a|(?<b>b)/',
26+
fn (array $match) => $match['b'] !== null ? 'aa' : 'possible?',
27+
'abcd',
28+
flags: PREG_UNMATCHED_AS_NULL,
29+
);
30+
}

0 commit comments

Comments
 (0)