1
0
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:
Matthew Brown 2020-03-12 11:42:01 -04:00
parent c6a5781e78
commit 5210f9b69b
2 changed files with 37 additions and 0 deletions

View File

@ -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;
}

View File

@ -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();'
],
];
}