mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix #4266 - prevent OOM when analysing closure unioned with invokable class
This commit is contained in:
parent
6ad5e1c013
commit
c9e47450a7
@ -695,7 +695,8 @@ class FunctionCallAnalyzer extends CallAnalyzer
|
|||||||
$stmt,
|
$stmt,
|
||||||
$real_stmt,
|
$real_stmt,
|
||||||
$function_name,
|
$function_name,
|
||||||
$context
|
$context,
|
||||||
|
$var_type_part
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -746,7 +747,8 @@ class FunctionCallAnalyzer extends CallAnalyzer
|
|||||||
PhpParser\Node\Expr\FuncCall $stmt,
|
PhpParser\Node\Expr\FuncCall $stmt,
|
||||||
PhpParser\Node\Expr\FuncCall $real_stmt,
|
PhpParser\Node\Expr\FuncCall $real_stmt,
|
||||||
PhpParser\Node\Expr $function_name,
|
PhpParser\Node\Expr $function_name,
|
||||||
Context $context
|
Context $context,
|
||||||
|
Type\Atomic $atomic_type
|
||||||
) : void {
|
) : void {
|
||||||
$old_data_provider = $statements_analyzer->node_data;
|
$old_data_provider = $statements_analyzer->node_data;
|
||||||
|
|
||||||
@ -772,6 +774,8 @@ class FunctionCallAnalyzer extends CallAnalyzer
|
|||||||
$statements_analyzer->addSuppressedIssues(['PossiblyInvalidMethodCall']);
|
$statements_analyzer->addSuppressedIssues(['PossiblyInvalidMethodCall']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$statements_analyzer->node_data->setType($function_name, new Type\Union([$atomic_type]));
|
||||||
|
|
||||||
\Psalm\Internal\Analyzer\Statements\Expression\Call\MethodCallAnalyzer::analyze(
|
\Psalm\Internal\Analyzer\Statements\Expression\Call\MethodCallAnalyzer::analyze(
|
||||||
$statements_analyzer,
|
$statements_analyzer,
|
||||||
$fake_method_call,
|
$fake_method_call,
|
||||||
|
@ -45,7 +45,15 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
|
|||||||
$was_inside_use = $context->inside_use;
|
$was_inside_use = $context->inside_use;
|
||||||
$context->inside_use = true;
|
$context->inside_use = true;
|
||||||
|
|
||||||
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->var, $context) === false) {
|
$existing_stmt_var_type = null;
|
||||||
|
|
||||||
|
if (!$real_method_call) {
|
||||||
|
$existing_stmt_var_type = $statements_analyzer->node_data->getType($stmt->var);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($existing_stmt_var_type) {
|
||||||
|
$statements_analyzer->node_data->setType($stmt->var, $existing_stmt_var_type);
|
||||||
|
} elseif (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->var, $context) === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,6 +575,38 @@ class ReturnTypeManipulationTest extends FileManipulationTest
|
|||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
],
|
],
|
||||||
|
'dontOOM' => [
|
||||||
|
'<?php
|
||||||
|
class FC {
|
||||||
|
public function __invoke() : void {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo(): string {
|
||||||
|
if (rand(0, 1)) {
|
||||||
|
$cb = new FC();
|
||||||
|
} else {
|
||||||
|
$cb = function() {};
|
||||||
|
}
|
||||||
|
$cb();
|
||||||
|
}',
|
||||||
|
'<?php
|
||||||
|
class FC {
|
||||||
|
public function __invoke() : void {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo(): string {
|
||||||
|
if (rand(0, 1)) {
|
||||||
|
$cb = new FC();
|
||||||
|
} else {
|
||||||
|
$cb = function() {};
|
||||||
|
}
|
||||||
|
$cb();
|
||||||
|
}',
|
||||||
|
'7.3',
|
||||||
|
['InvalidReturnType'],
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user