1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #1764 - prevent UndefinedInterfaceMethod error when checking initialisation

This commit is contained in:
Matthew Brown 2019-06-09 09:17:45 -04:00
parent 5592335a7c
commit 93f81f599e
2 changed files with 62 additions and 0 deletions

View File

@ -779,6 +779,14 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer implements Statements
'TypeDoesNotContainType',
'LoopInvalidation',
]);
if ($context->collect_initializations) {
$statements_analyzer->addSuppressedIssues([
'UndefinedInterfaceMethod',
'UndefinedMethod',
'PossiblyUndefinedMethod',
]);
}
}
$statements_analyzer->analyze($function_stmts, $context, $global_context, true);

View File

@ -1561,6 +1561,34 @@ class PropertyTypeTest extends TestCase
class Bar extends Foo {}',
],
'parentSetsWiderTypeInConstructor' => [
'<?php
interface Foo {}
interface FooMore extends Foo {
public function something(): void;
}
class Bar {
/** @var Foo */
protected $foo;
public function __construct(Foo $foo) {
$this->foo = $foo;
}
}
class BarMore extends Bar {
/** @var FooMore */
protected $foo;
public function __construct(FooMore $foo) {
parent::__construct($foo);
$this->foo->something();
}
}'
],
];
}
@ -2386,6 +2414,32 @@ class PropertyTypeTest extends TestCase
}',
'error_message' => 'PropertyNotSetInConstructor'
],
'parentSetsWiderTypeInConstructor' => [
'<?php
interface Foo {}
interface FooMore extends Foo {}
class Bar {
/** @var Foo */
protected $foo;
public function __construct(Foo $foo) {
$this->foo = $foo;
}
}
class BarMore extends Bar {
/** @var FooMore */
protected $foo;
public function __construct(FooMore $foo) {
parent::__construct($foo);
$this->foo->something();
}
}',
'error_message' => 'UndefinedInterfaceMethod'
],
];
}
}