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:
parent
fffbccdacb
commit
a615f4423b
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
interface Bar {}
|
||||
interface Bar { public function makeBar(): void; }
|
||||
|
||||
class Foo
|
||||
{
|
||||
|
@ -125,7 +125,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
||||
$add_mutations = false,
|
||||
array $byref_uses = null
|
||||
) {
|
||||
var_dump('FunctionLikeAnalyzer::analyze');
|
||||
$storage = $this->storage;
|
||||
|
||||
$function_stmts = $this->function->getStmts() ?: [];
|
||||
@ -170,14 +169,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
||||
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();
|
||||
|
||||
$method_id = $this->getMethodId($context->self);
|
||||
@ -551,8 +542,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
||||
|
||||
$this->examineParamTypes($statements_analyzer, $context, $codebase);
|
||||
|
||||
$this->examineSelfOut($statements_analyzer, $context, $codebase);
|
||||
|
||||
foreach ($storage->params as $offset => $function_param) {
|
||||
// only complain if there's no type defined by a parent type
|
||||
if (!$function_param->type
|
||||
@ -1520,11 +1509,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
//var_dump($actual_type->getId());
|
||||
//var_dump($context);
|
||||
//die;
|
||||
// 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
|
||||
*/
|
||||
|
@ -1303,13 +1303,6 @@ class AssignmentAnalyzer
|
||||
$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 (!$by_ref_type->hasMixed() && $constrain_type) {
|
||||
$context->byref_constraints[$var_id] = new \Psalm\Internal\ReferenceConstraint($by_ref_type);
|
||||
|
@ -829,13 +829,9 @@ class ArgumentsAnalyzer
|
||||
]);
|
||||
}
|
||||
}
|
||||
//var_dump($by_ref_type);die;
|
||||
|
||||
$by_ref_type = $by_ref_type ?: Type::getMixed();
|
||||
|
||||
//var_dump($by_ref_type);
|
||||
//var_dump($by_ref_out_type);
|
||||
|
||||
AssignmentAnalyzer::assignByRefParam(
|
||||
$statements_analyzer,
|
||||
$arg->value,
|
||||
|
@ -62,7 +62,6 @@ class FunctionCallAnalyzer extends CallAnalyzer
|
||||
Context $context
|
||||
) : bool {
|
||||
$function_name = $stmt->name;
|
||||
var_dump($function_name);
|
||||
|
||||
$function_id = null;
|
||||
$function_params = null;
|
||||
|
@ -167,6 +167,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
|
||||
$result = new Method\AtomicMethodCallAnalysisResult();
|
||||
|
||||
$possible_new_class_types = [];
|
||||
$fq_class_name = null;
|
||||
foreach ($lhs_types as $lhs_type_part) {
|
||||
Method\AtomicMethodCallAnalyzer::analyze(
|
||||
$statements_analyzer,
|
||||
@ -187,6 +188,8 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
|
||||
&& !$possible_new_class_type->equals($class_type)) {
|
||||
$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) {
|
||||
@ -404,25 +407,13 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
|
||||
$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_id = new \Psalm\Internal\MethodIdentifier($fq_class_name, strtolower($method_name));
|
||||
$declaring_method_id = $codebase->methods->getDeclaringMethodId($method_id);
|
||||
var_dump($declaring_method_id);
|
||||
$storage = $codebase->methods->getStorage($declaring_method_id);
|
||||
die;
|
||||
*/
|
||||
$foo_id = '$foo';
|
||||
$context->vars_possibly_in_scope[$foo_id] = true;
|
||||
$context->vars_in_scope[$foo_id] = new Type\Union([new Type\Atomic\TInt()]);
|
||||
$storage = $codebase->methods->getStorage($method_id);
|
||||
if ($storage->self_out_type) {
|
||||
// TODO: Nedd clone?
|
||||
$context->vars_in_scope[$lhs_var_id] = clone $storage->self_out_type;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user