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

Fix bugs in refactor

This commit is contained in:
Matthew Brown 2016-10-10 01:35:12 -04:00
parent f68280488c
commit a30c82e5d7
5 changed files with 34 additions and 15 deletions

View File

@ -8,6 +8,11 @@ use Psalm\Context;
class ClassChecker extends ClassLikeChecker
{
/**
* @var PhpParser\Node\Stmt\Class_
*/
protected $class;
/**
* A lookup table of existing classes
* @var array

View File

@ -325,7 +325,7 @@ class FunctionChecker extends FunctionLikeChecker
new Type\Generic('array',
[
Type::getInt(),
clone $call_args[0]->value->inferredType->type_paams[1]
clone $call_args[0]->value->inferredType->types['array']->type_params[1]
]
)
]);

View File

@ -535,8 +535,8 @@ abstract class FunctionLikeChecker implements StatementsSource
$param_name,
$param->isPassedByReference(),
$param_type,
$is_nullable,
$is_optional
$is_optional,
$is_nullable
);
}

View File

@ -1546,7 +1546,7 @@ class StatementsChecker
}
if ($var_id) {
$context->vars_in_scope[$var_id] = $stmt->inferredType;
$context->vars_in_scope[$var_id] = isset($stmt->inferredType) ? $stmt->inferredType : Type::getMixed();
}
}
@ -1722,15 +1722,29 @@ class StatementsChecker
);
if (!isset($class_properties[$prop_name])) {
if (IssueBuffer::accepts(
new UndefinedProperty(
'Instance property ' . $lhs_type_part->value . '::' . $prop_name . ' is not defined',
$this->checked_file_name,
$stmt->getLine()
),
$this->suppressed_issues
)) {
return false;
if ($stmt->var->name === 'this') {
if (IssueBuffer::accepts(
new UndefinedThisProperty(
'Instance property ' . $lhs_type_part->value . '::' . $prop_name . ' is not defined',
$this->checked_file_name,
$stmt->getLine()
),
$this->suppressed_issues
)) {
return false;
}
}
else {
if (IssueBuffer::accepts(
new UndefinedProperty(
'Instance property ' . $lhs_type_part->value . '::' . $prop_name . ' is not defined',
$this->checked_file_name,
$stmt->getLine()
),
$this->suppressed_issues
)) {
return false;
}
}
continue;
@ -3204,7 +3218,7 @@ class StatementsChecker
foreach ($args as $i => $arg) {
$method_param = $method_params[$i];
if ($return_type->value === '$' . $method_param['name']) {
if ($return_type->value === '$' . $method_param->name) {
$arg_value = $arg->value;
if ($arg_value instanceof PhpParser\Node\Scalar\String_) {
$return_type->value = preg_replace('/^\\\/', '', $arg_value->value);

View File

@ -19,7 +19,7 @@ class FunctionLikeParameter
/** @var bool */
public $is_nullable;
public function __construct($name, $by_ref, $type, $is_optional = false, $is_nullable = false)
public function __construct($name, $by_ref, $type, $is_optional = true, $is_nullable = false)
{
$this->name = $name;
$this->by_ref = $by_ref;