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

Fix #1045 - check intersection classes exist

This commit is contained in:
Brown 2018-10-30 10:34:02 -04:00
parent d1baff4b92
commit aef9fecaa3
2 changed files with 41 additions and 0 deletions

View File

@ -418,6 +418,17 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
$method_id = $intersection_type->value . '::' . $method_name_lc;
$fq_class_name = $intersection_type->value;
$does_class_exist = ClassLikeChecker::checkFullyQualifiedClassLikeName(
$statements_checker,
$fq_class_name,
new CodeLocation($source, $stmt->var),
$statements_checker->getSuppressedIssues()
);
if (!$does_class_exist) {
return false;
}
if ($codebase->methodExists($method_id)) {
break;
}

View File

@ -343,6 +343,36 @@ class AssertTest extends TestCase
}',
'error_message' => 'InvalidScalarArgument',
],
'noFatalForUnknownAssertClass' => [
'<?php
interface Foo {}
class Bar implements Foo {
public function sayHello(): void {
echo "Hello";
}
}
/**
* @param mixed $value
* @param class-string $type
* @psalm-assert SomeUndefinedClass $value
*/
function assertInstanceOf($value, string $type): void {
// some code
}
// Returns concreate implmenetation of Foo, which in this case is Bar
function getImplementationOfFoo(): Foo {
return new Bar();
}
$bar = getImplementationOfFoo();
assertInstanceOf($bar, Bar::class);
$bar->sayHello();',
'error_message' => 'UndefinedClass',
],
];
}
}