From a30c82e5d70539eab172d858e082056d9e8f0bc3 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Mon, 10 Oct 2016 01:35:12 -0400 Subject: [PATCH] Fix bugs in refactor --- src/Psalm/Checker/ClassChecker.php | 5 ++++ src/Psalm/Checker/FunctionChecker.php | 2 +- src/Psalm/Checker/FunctionLikeChecker.php | 4 +-- src/Psalm/Checker/StatementsChecker.php | 36 ++++++++++++++++------- src/Psalm/FunctionLikeParameter.php | 2 +- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/Psalm/Checker/ClassChecker.php b/src/Psalm/Checker/ClassChecker.php index cffa08635..7e753f2f3 100644 --- a/src/Psalm/Checker/ClassChecker.php +++ b/src/Psalm/Checker/ClassChecker.php @@ -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 diff --git a/src/Psalm/Checker/FunctionChecker.php b/src/Psalm/Checker/FunctionChecker.php index 72a29bf44..a2daceb7a 100644 --- a/src/Psalm/Checker/FunctionChecker.php +++ b/src/Psalm/Checker/FunctionChecker.php @@ -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] ] ) ]); diff --git a/src/Psalm/Checker/FunctionLikeChecker.php b/src/Psalm/Checker/FunctionLikeChecker.php index b35547a1a..7e24c6f30 100644 --- a/src/Psalm/Checker/FunctionLikeChecker.php +++ b/src/Psalm/Checker/FunctionLikeChecker.php @@ -535,8 +535,8 @@ abstract class FunctionLikeChecker implements StatementsSource $param_name, $param->isPassedByReference(), $param_type, - $is_nullable, - $is_optional + $is_optional, + $is_nullable ); } diff --git a/src/Psalm/Checker/StatementsChecker.php b/src/Psalm/Checker/StatementsChecker.php index 30005ad05..4fadbdb03 100644 --- a/src/Psalm/Checker/StatementsChecker.php +++ b/src/Psalm/Checker/StatementsChecker.php @@ -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); diff --git a/src/Psalm/FunctionLikeParameter.php b/src/Psalm/FunctionLikeParameter.php index 0375111cb..eee68bae3 100644 --- a/src/Psalm/FunctionLikeParameter.php +++ b/src/Psalm/FunctionLikeParameter.php @@ -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;