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

Remove more false positives

This commit is contained in:
Matthew Brown 2017-02-08 02:23:17 -05:00
parent cedb70b0b4
commit 64cbe005f3
3 changed files with 17 additions and 3 deletions

View File

@ -203,6 +203,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
} }
$class_context->vars_in_scope['$this'] = new Type\Union([new TNamedObject($this->fq_class_name)]); $class_context->vars_in_scope['$this'] = new Type\Union([new TNamedObject($this->fq_class_name)]);
$class_context->vars_possibly_in_scope['$this'] = true;
} }
// set all constants first // set all constants first
@ -551,6 +552,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
$method_context = clone $class_context; $method_context = clone $class_context;
$method_context->collect_initializations = true; $method_context->collect_initializations = true;
$method_context->vars_in_scope['$this'] = Type::parseString($fq_class_name); $method_context->vars_in_scope['$this'] = Type::parseString($fq_class_name);
$method_context->vars_possibly_in_scope['$this'] = true;
$constructor_checker->analyze($method_context, null, true); $constructor_checker->analyze($method_context, null, true);

View File

@ -134,6 +134,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
} }
} elseif ($context->self) { } elseif ($context->self) {
$context->vars_in_scope['$this'] = new Type\Union([new TNamedObject($context->self)]); $context->vars_in_scope['$this'] = new Type\Union([new TNamedObject($context->self)]);
$context->vars_possibly_in_scope['$this'] = true;
} }
$declaring_method_id = (string)MethodChecker::getDeclaringMethodId($method_id); $declaring_method_id = (string)MethodChecker::getDeclaringMethodId($method_id);
@ -311,9 +312,17 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
$param_type->check($this->source, $function_param->code_location, $this->suppressed_issues); $param_type->check($this->source, $function_param->code_location, $this->suppressed_issues);
$context->vars_in_scope['$' . $function_param->name] = $param_type; $context->vars_in_scope['$' . $function_param->name] = $param_type;
$context->vars_possibly_in_scope['$' . $function_param->name] = true;
if ($function_param->by_ref) {
// register by ref params as having been used, to avoid false positives
// @todo change the assignment analysis *just* for byref params
// so that we don't have to do this
$context->hasVariable('$' . $function_param->name);
}
$statements_checker->registerVariable( $statements_checker->registerVariable(
$function_param->name, '$' . $function_param->name,
$function_param->code_location $function_param->code_location
); );
} }
@ -352,7 +361,10 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
$var_name !== '$this' && $var_name !== '$this' &&
strpos($var_name, '::$') === false && strpos($var_name, '::$') === false &&
strpos($var_name, '[') === false && strpos($var_name, '[') === false &&
$var_name !== '$_' $var_name !== '$_' &&
(!isset($storage->param_types[substr($var_name, 1)]) ||
!$storage instanceof MethodStorage ||
$storage->visibility === ClassLikeChecker::VISIBILITY_PRIVATE)
) { ) {
$original_location = $statements_checker->getFirstAppearance($var_name); $original_location = $statements_checker->getFirstAppearance($var_name);

View File

@ -291,7 +291,7 @@ class Context
public function hasVariable($var_name) public function hasVariable($var_name)
{ {
if ($this->count_references) { if ($this->count_references) {
if (!$var_name) { if (!$var_name || !isset($this->vars_possibly_in_scope[$var_name])) {
return false; return false;
} }