1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix tests

This commit is contained in:
Matthew Brown 2020-02-21 22:15:25 -05:00
parent 7d99a15072
commit 4707b21227
5 changed files with 26 additions and 8 deletions

View File

@ -79,6 +79,13 @@ class Context
*/
public $inside_call = false;
/**
* Whether or not we're inside a throw
*
* @var bool
*/
public $inside_throw = false;
/**
* Whether or not we're inside an assignment
*

View File

@ -439,7 +439,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
if ($declaring_method_id) {
$method_storage = $codebase->methods->getStorage($declaring_method_id);
if (!$method_storage->external_mutation_free) {
if (!$method_storage->external_mutation_free && !$context->inside_throw) {
if (IssueBuffer::accepts(
new ImpureMethodCall(
'Cannot call an impure constructor from a pure context',

View File

@ -1397,14 +1397,12 @@ class CallAnalyzer
return false;
}
if ((($function_storage
&& $function_storage->mutation_free
&& (!$function_storage instanceof \Psalm\Storage\MethodStorage
|| !$function_storage->mutation_free_inferred))
|| ($class_storage
&& $class_storage->mutation_free))
&& !$statements_analyzer->node_data->isPureCompatible($arg->value)
if ($class_storage
&& $class_storage->mutation_free
&& $function_storage
&& $function_storage->cased_name === '__construct'
&& ($node_type = $statements_analyzer->node_data->getType($arg->value))
&& !$context->inside_throw
) {
foreach ($node_type->getAtomicTypes() as $atomic_arg_type) {
if ($atomic_arg_type instanceof Type\Atomic\TNamedObject) {

View File

@ -24,9 +24,11 @@ class ThrowAnalyzer
PhpParser\Node\Stmt\Throw_ $stmt,
Context $context
) {
$context->inside_throw = true;
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) {
return false;
}
$context->inside_throw = false;
if ($context->check_classes
&& ($throw_type = $statements_analyzer->node_data->getType($stmt->expr))

View File

@ -306,8 +306,19 @@ class ClassTemplateCovarianceTest extends TestCase
],
'allowImmutableCovariance' => [
'<?php
/**
* @psalm-immutable
*/
class Animal {}
/**
* @psalm-immutable
*/
class Dog extends Animal{}
/**
* @psalm-immutable
*/
class Cat extends Animal{}
/**