Skip to content

Commit

Permalink
Do not check errored definitions’ type
Browse files Browse the repository at this point in the history
  • Loading branch information
MatTheCat committed May 5, 2023
1 parent bb7b798 commit 4645e03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Compiler/CheckTypeDeclarationsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
$class = null;

if ($value instanceof Definition) {
if ($value->getFactory()) {
if ($value->hasErrors() || $value->getFactory()) {
return;
}

Expand Down
15 changes: 15 additions & 0 deletions Tests/Compiler/CheckTypeDeclarationsPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Bar;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarErroredDependency;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgument;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgumentNotNull;
Expand Down Expand Up @@ -1010,6 +1011,20 @@ public function testIgnoreDefinitionFactoryArgument()

$this->addToAssertionCount(1);
}

public function testErroredDefinitionsAreNotChecked()
{
$container = new ContainerBuilder();
$container->register('errored_dependency', BarErroredDependency::class)
->setArguments([
(new Definition(Foo::class))
->addError('error'),
]);

(new CheckTypeDeclarationsPass(true))->process($container);

$this->addToAssertionCount(1);
}
}

class CallableClass
Expand Down
10 changes: 10 additions & 0 deletions Tests/Fixtures/CheckTypeDeclarationsPass/BarErroredDependency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass;

class BarErroredDependency
{
public function __construct(\stdClass $foo)
{
}
}

0 comments on commit 4645e03

Please sign in to comment.