mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix #2966 - register constructor use for new $templated_class
This commit is contained in:
parent
c6a5781e78
commit
5210f9b69b
@ -150,6 +150,20 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
|
||||
}
|
||||
}
|
||||
|
||||
if ($lhs_type_part->as_type) {
|
||||
$codebase->methods->methodExists(
|
||||
new \Psalm\Internal\MethodIdentifier(
|
||||
$lhs_type_part->as_type->value,
|
||||
'__construct'
|
||||
),
|
||||
$context->calling_function_id,
|
||||
$context->collect_references
|
||||
? new CodeLocation($statements_analyzer->getSource(), $stmt) : null,
|
||||
$statements_analyzer,
|
||||
$statements_analyzer->getFilePath()
|
||||
);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -683,6 +683,29 @@ class UnusedCodeTest extends TestCase
|
||||
/** @psalm-suppress MixedAssignment */
|
||||
foreach ($items as $_item) {}'
|
||||
],
|
||||
'usedThroughNewClassStringOfBase' => [
|
||||
'<?php
|
||||
abstract class FooBase {
|
||||
public final function __construct() {}
|
||||
|
||||
public function baz() : void {
|
||||
echo "hello";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-template T as FooBase
|
||||
* @psalm-param class-string<T> $type
|
||||
* @psalm-return T
|
||||
*/
|
||||
function createFoo($type): FooBase {
|
||||
return new $type();
|
||||
}
|
||||
|
||||
class Foo extends FooBase {}
|
||||
|
||||
createFoo(Foo::class)->baz();'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user