1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 09:19:40 +01:00

More work on self-out (WIP)

This commit is contained in:
Olle 2020-06-21 23:06:04 +00:00
parent fffbccdacb
commit a615f4423b
6 changed files with 9 additions and 57 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
interface Bar {} interface Bar { public function makeBar(): void; }
class Foo class Foo
{ {

View File

@ -125,7 +125,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
$add_mutations = false, $add_mutations = false,
array $byref_uses = null array $byref_uses = null
) { ) {
var_dump('FunctionLikeAnalyzer::analyze');
$storage = $this->storage; $storage = $this->storage;
$function_stmts = $this->function->getStmts() ?: []; $function_stmts = $this->function->getStmts() ?: [];
@ -170,14 +169,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
throw new \UnexpectedValueException('$storage must be MethodStorage'); throw new \UnexpectedValueException('$storage must be MethodStorage');
} }
//var_dump($context->vars_in_scope);
//var_dump($storage->self_out_type);
//$var_id = '$foo';
//$context->byref_constraints[$var_id] = new \Psalm\Internal\ReferenceConstraint($by_ref_type);
//$context->vars_possibly_in_scope[$var_id] = true;
//$context->vars_in_scope[$var_id] = new Type\Union([new Type\Atomic\TInt()]);
//return;
$real_method_id = $this->getMethodId(); $real_method_id = $this->getMethodId();
$method_id = $this->getMethodId($context->self); $method_id = $this->getMethodId($context->self);
@ -551,8 +542,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
$this->examineParamTypes($statements_analyzer, $context, $codebase); $this->examineParamTypes($statements_analyzer, $context, $codebase);
$this->examineSelfOut($statements_analyzer, $context, $codebase);
foreach ($storage->params as $offset => $function_param) { foreach ($storage->params as $offset => $function_param) {
// only complain if there's no type defined by a parent type // only complain if there's no type defined by a parent type
if (!$function_param->type if (!$function_param->type
@ -1520,11 +1509,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
), ),
$statements_analyzer->getSuppressedIssues() $statements_analyzer->getSuppressedIssues()
)) { )) {
//var_dump($actual_type->getId());
//var_dump($context);
//die;
// fall through // fall through
//throw new \Exception('there');
} }
} }
} }
@ -1532,18 +1517,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
} }
} }
public function examineSelfOut(
StatementsAnalyzer $statements_analyzer,
Context $context,
Codebase $codebase,
PhpParser\Node $stmt = null
) {
$storage = $this->getFunctionLikeStorage($statements_analyzer);
if ($storage->self_out_type) {
var_dump($context->vars_in_scope);
}
}
/** /**
* @return null|string * @return null|string
*/ */

View File

@ -1303,13 +1303,6 @@ class AssignmentAnalyzer
$statements_analyzer $statements_analyzer
); );
$foo_id = '$foo';
$context->byref_constraints[$foo_id] = new \Psalm\Internal\ReferenceConstraint($by_ref_type);
$context->vars_possibly_in_scope[$foo_id] = true;
$context->vars_in_scope[$foo_id] = new Type\Union([new Type\Atomic\TInt()]);
die;
//return;
if ($var_id) { if ($var_id) {
if (!$by_ref_type->hasMixed() && $constrain_type) { if (!$by_ref_type->hasMixed() && $constrain_type) {
$context->byref_constraints[$var_id] = new \Psalm\Internal\ReferenceConstraint($by_ref_type); $context->byref_constraints[$var_id] = new \Psalm\Internal\ReferenceConstraint($by_ref_type);

View File

@ -829,13 +829,9 @@ class ArgumentsAnalyzer
]); ]);
} }
} }
//var_dump($by_ref_type);die;
$by_ref_type = $by_ref_type ?: Type::getMixed(); $by_ref_type = $by_ref_type ?: Type::getMixed();
//var_dump($by_ref_type);
//var_dump($by_ref_out_type);
AssignmentAnalyzer::assignByRefParam( AssignmentAnalyzer::assignByRefParam(
$statements_analyzer, $statements_analyzer,
$arg->value, $arg->value,

View File

@ -62,7 +62,6 @@ class FunctionCallAnalyzer extends CallAnalyzer
Context $context Context $context
) : bool { ) : bool {
$function_name = $stmt->name; $function_name = $stmt->name;
var_dump($function_name);
$function_id = null; $function_id = null;
$function_params = null; $function_params = null;

View File

@ -167,6 +167,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
$result = new Method\AtomicMethodCallAnalysisResult(); $result = new Method\AtomicMethodCallAnalysisResult();
$possible_new_class_types = []; $possible_new_class_types = [];
$fq_class_name = null;
foreach ($lhs_types as $lhs_type_part) { foreach ($lhs_types as $lhs_type_part) {
Method\AtomicMethodCallAnalyzer::analyze( Method\AtomicMethodCallAnalyzer::analyze(
$statements_analyzer, $statements_analyzer,
@ -187,6 +188,8 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
&& !$possible_new_class_type->equals($class_type)) { && !$possible_new_class_type->equals($class_type)) {
$possible_new_class_types[] = $context->vars_in_scope[$lhs_var_id]; $possible_new_class_types[] = $context->vars_in_scope[$lhs_var_id];
} }
// TODO: How?
$fq_class_name = $lhs_type_part->value;
} }
if (count($possible_new_class_types) > 0) { if (count($possible_new_class_types) > 0) {
@ -404,25 +407,13 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
$context->vars_in_scope[$lhs_var_id] = $class_type; $context->vars_in_scope[$lhs_var_id] = $class_type;
} }
/*
var_dump($lhs_var_id);
var_dump($stmt->name);
var_dump($stmt->var);
var_dump($class_type);
$fq_class_name = (string)$source->getFQCLN();
var_dump($fq_class_name);
die;
$lhs_types = $class_type->getAtomicTypes();
$method_name = $stmt->name->name; $method_name = $stmt->name->name;
$method_id = new \Psalm\Internal\MethodIdentifier($fq_class_name, strtolower($method_name)); $method_id = new \Psalm\Internal\MethodIdentifier($fq_class_name, strtolower($method_name));
$declaring_method_id = $codebase->methods->getDeclaringMethodId($method_id); $storage = $codebase->methods->getStorage($method_id);
var_dump($declaring_method_id); if ($storage->self_out_type) {
$storage = $codebase->methods->getStorage($declaring_method_id); // TODO: Nedd clone?
die; $context->vars_in_scope[$lhs_var_id] = clone $storage->self_out_type;
*/ }
$foo_id = '$foo';
$context->vars_possibly_in_scope[$foo_id] = true;
$context->vars_in_scope[$foo_id] = new Type\Union([new Type\Atomic\TInt()]);
return true; return true;
} }