1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #53 - add back extends checks for reflected classes

This commit is contained in:
Matthew Brown 2017-01-14 19:34:10 -05:00
parent 804de9f215
commit 78c1138a94
4 changed files with 46 additions and 14 deletions

View File

@ -116,7 +116,7 @@ class ClassChecker extends ClassLikeChecker
throw new \UnexpectedValueException('$storage should not be null for ' . $fq_class_name);
}
return in_array($possible_parent, self::$storage[$fq_class_name]->parent_classes);
return in_array(strtolower($possible_parent), self::$storage[$fq_class_name]->parent_classes);
}
/**

View File

@ -577,7 +577,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
$storage->public_class_constants = $parent_storage->public_class_constants;
$storage->protected_class_constants = $parent_storage->protected_class_constants;
$storage->parent_classes = array_merge([$parent_class], $parent_storage->parent_classes);
$storage->parent_classes = array_merge([strtolower($parent_class)], $parent_storage->parent_classes);
$storage->used_traits = $parent_storage->used_traits;
@ -1067,6 +1067,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
$storage->public_class_constants = $parent_storage->public_class_constants;
$storage->protected_class_constants = $parent_storage->protected_class_constants;
$storage->parent_classes = array_merge([strtolower($parent_class_name)], $parent_storage->parent_classes);
$storage->used_traits = $parent_storage->used_traits;
}

View File

@ -643,18 +643,30 @@ class TypeChecker
return $new_type;
}
if (!InterfaceChecker::interfaceExists($new_var_type, $file_checker) &&
!TypeChecker::isContainedBy($new_type, $existing_var_type, $file_checker) &&
!TypeChecker::isContainedBy($existing_var_type, $new_type, $file_checker) &&
$code_location) {
if (IssueBuffer::accepts(
new TypeDoesNotContainType(
'Cannot resolve types for ' . $key . ' - ' . $existing_var_type . ' does not contain ' . $new_type,
$code_location
),
$suppressed_issues
)) {
// fall through
if (!InterfaceChecker::interfaceExists($new_var_type, $file_checker) && $code_location) {
$has_match = false;
foreach ($existing_var_type->types as $existing_var_type_part) {
$dummy_type = new Type\Union([$existing_var_type_part]);
if (TypeChecker::isContainedBy($new_type, $dummy_type, $file_checker) ||
TypeChecker::isContainedBy($dummy_type, $new_type, $file_checker)) {
$has_match = true;
break;
}
}
if (!$has_match) {
if (IssueBuffer::accepts(
new TypeDoesNotContainType(
'Cannot resolve types for ' . $key . ' - ' . $existing_var_type .
' does not contain ' . $new_type,
$code_location
),
$suppressed_issues
)) {
// fall through
}
}
}

View File

@ -418,4 +418,23 @@ class ClassTest extends PHPUnit_Framework_TestCase
$context = new Context('somefile.php');
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @return void
*/
public function testReflectedParents()
{
$stmts = self::$parser->parse('<?php
$e = rand(0, 10)
? new RuntimeException("m")
: null;
if ($e instanceof Exception) {
echo "good";
}
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context('somefile.php');
$file_checker->visitAndAnalyzeMethods($context);
}
}