Skip to content

Commit 1471b16

Browse files
committed
[ErrorHandler] Do not patch return statements in closures
1 parent 51374a6 commit 1471b16

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

DebugClassLoader.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,20 @@ private function fixReturnStatements(\ReflectionMethod $method, string $returnTy
10901090
}
10911091

10921092
$end = $method->isGenerator() ? $i : $method->getEndLine();
1093+
$inClosure = false;
1094+
$braces = 0;
10931095
for (; $i < $end; ++$i) {
1096+
if (!$inClosure) {
1097+
$inClosure = str_contains($code[$i], 'function (');
1098+
}
1099+
1100+
if ($inClosure) {
1101+
$braces += substr_count($code[$i], '{') - substr_count($code[$i], '}');
1102+
$inClosure = $braces > 0;
1103+
1104+
continue;
1105+
}
1106+
10941107
if ('void' === $returnType) {
10951108
$fixedCode[$i] = str_replace(' return null;', ' return;', $code[$i]);
10961109
} elseif ('mixed' === $returnType || '?' === $returnType[0]) {

0 commit comments

Comments
 (0)