mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Add by-reference clause removal
This commit is contained in:
parent
a09e668dbc
commit
075cc5f50d
@ -608,6 +608,15 @@ class ExpressionChecker
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$existing_type = $context->vars_in_scope[$var_id];
|
$existing_type = $context->vars_in_scope[$var_id];
|
||||||
|
|
||||||
|
// removes dependennt vars from $context
|
||||||
|
$context->removeDescendents(
|
||||||
|
$var_id,
|
||||||
|
$existing_type,
|
||||||
|
$by_ref_type,
|
||||||
|
$statements_checker->getFileChecker()
|
||||||
|
);
|
||||||
|
|
||||||
if ((string)$existing_type !== 'array<empty, empty>') {
|
if ((string)$existing_type !== 'array<empty, empty>') {
|
||||||
$context->vars_in_scope[$var_id] = $by_ref_type;
|
$context->vars_in_scope[$var_id] = $by_ref_type;
|
||||||
$stmt->inferredType = $context->vars_in_scope[$var_id];
|
$stmt->inferredType = $context->vars_in_scope[$var_id];
|
||||||
|
@ -607,4 +607,29 @@ class TypeAlgebraTest extends PHPUnit_Framework_TestCase
|
|||||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||||
$file_checker->visitAndAnalyzeMethods();
|
$file_checker->visitAndAnalyzeMethods();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testByRefAssignment()
|
||||||
|
{
|
||||||
|
$stmts = self::$parser->parse('<?php
|
||||||
|
function foo() : void {
|
||||||
|
$matches = rand(0, 1) ? ["hello"] : null;
|
||||||
|
|
||||||
|
if (!$matches) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
preg_match("/hello/", "hello dolly", $matches);
|
||||||
|
|
||||||
|
if ($matches) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
');
|
||||||
|
|
||||||
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||||
|
$file_checker->visitAndAnalyzeMethods();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user