mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #4064 - assume most iterators are impure
This commit is contained in:
parent
57ac0a3310
commit
20e004744f
@ -502,6 +502,30 @@ class ForeachAnalyzer
|
||||
$value_type,
|
||||
Type::getMixed()
|
||||
);
|
||||
|
||||
if (!$context->pure) {
|
||||
$project_analyzer = $statements_analyzer->getProjectAnalyzer();
|
||||
|
||||
if ($codebase->alter_code
|
||||
&& (isset($project_analyzer->getIssuesToFix()['MissingPureAnnotation'])
|
||||
|| isset($project_analyzer->getIssuesToFix()['MissingImmutableAnnotation']))
|
||||
&& $statements_analyzer->getSource()
|
||||
instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer
|
||||
) {
|
||||
$statements_analyzer->getSource()->inferred_has_mutation = true;
|
||||
$statements_analyzer->getSource()->inferred_impure = true;
|
||||
}
|
||||
} else {
|
||||
if (IssueBuffer::accepts(
|
||||
new ImpureMethodCall(
|
||||
'Cannot call a possibly-mutating iterator from a pure context',
|
||||
new CodeLocation($statements_analyzer, $stmt)
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
} elseif ($iterator_atomic_type instanceof Type\Atomic\TIterable) {
|
||||
if ($iterator_atomic_type->extra_types) {
|
||||
$iterator_atomic_type_copy = clone $iterator_atomic_type;
|
||||
@ -622,6 +646,30 @@ class ForeachAnalyzer
|
||||
} else {
|
||||
$raw_object_types[] = $iterator_atomic_type->value;
|
||||
}
|
||||
|
||||
if (!$context->pure) {
|
||||
$project_analyzer = $statements_analyzer->getProjectAnalyzer();
|
||||
|
||||
if ($codebase->alter_code
|
||||
&& (isset($project_analyzer->getIssuesToFix()['MissingPureAnnotation'])
|
||||
|| isset($project_analyzer->getIssuesToFix()['MissingImmutableAnnotation']))
|
||||
&& $statements_analyzer->getSource()
|
||||
instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer
|
||||
) {
|
||||
$statements_analyzer->getSource()->inferred_has_mutation = true;
|
||||
$statements_analyzer->getSource()->inferred_impure = true;
|
||||
}
|
||||
} else {
|
||||
if (IssueBuffer::accepts(
|
||||
new ImpureMethodCall(
|
||||
'Cannot call a possibly-mutating iterator from a pure context',
|
||||
new CodeLocation($statements_analyzer, $stmt)
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user