Skip to content

Commit 3866ff1

Browse files
committed
[DependencyInjection] Fix loop corruption in CheckTypeDeclarationsPass
1 parent c74df7a commit 3866ff1

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,14 @@ private function checkTypeDeclarations(Definition $checkedDefinition, \Reflectio
142142
if (!$p->hasType() || $p->isVariadic()) {
143143
continue;
144144
}
145+
$key = $i;
145146
if (\array_key_exists($p->name, $values)) {
146-
$i = $p->name;
147+
$key = $p->name;
147148
} elseif (!\array_key_exists($i, $values)) {
148149
continue;
149150
}
150151

151-
$this->checkType($checkedDefinition, $values[$i], $p, $envPlaceholderUniquePrefix);
152+
$this->checkType($checkedDefinition, $values[$key], $p, $envPlaceholderUniquePrefix);
152153
}
153154

154155
if ($reflectionFunction->isVariadic() && ($lastParameter = end($reflectionParameters))->hasType()) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,18 @@ public function testErroredDefinitionsAreNotChecked()
10231023

10241024
$this->addToAssertionCount(1);
10251025
}
1026+
1027+
public function testCheckTypeDeclarationsSkipsSubsequentNamedArguments()
1028+
{
1029+
$container = new ContainerBuilder();
1030+
$container->register('service', ServiceWithTwoInts::class)
1031+
->setArguments(['a' => 1, 'b' => []]);
1032+
1033+
$this->expectException(InvalidParameterTypeException::class);
1034+
$this->expectExceptionMessage('argument 2 of "Symfony\Component\DependencyInjection\Tests\Compiler\ServiceWithTwoInts::__construct()" accepts "int", "array" passed');
1035+
1036+
(new CheckTypeDeclarationsPass(true))->process($container);
1037+
}
10261038
}
10271039

10281040
class CallableClass
@@ -1038,3 +1050,10 @@ public static function __callStatic($name, $arguments)
10381050
{
10391051
}
10401052
}
1053+
1054+
class ServiceWithTwoInts
1055+
{
1056+
public function __construct(int $a, int $b)
1057+
{
1058+
}
1059+
}

0 commit comments

Comments
 (0)