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:
parent
5592335a7c
commit
93f81f599e
@ -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);
|
||||
|
@ -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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user