mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix tests
This commit is contained in:
parent
7d99a15072
commit
4707b21227
@ -79,6 +79,13 @@ class Context
|
|||||||
*/
|
*/
|
||||||
public $inside_call = false;
|
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
|
* Whether or not we're inside an assignment
|
||||||
*
|
*
|
||||||
|
@ -439,7 +439,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
|
|||||||
if ($declaring_method_id) {
|
if ($declaring_method_id) {
|
||||||
$method_storage = $codebase->methods->getStorage($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(
|
if (IssueBuffer::accepts(
|
||||||
new ImpureMethodCall(
|
new ImpureMethodCall(
|
||||||
'Cannot call an impure constructor from a pure context',
|
'Cannot call an impure constructor from a pure context',
|
||||||
|
@ -1397,14 +1397,12 @@ class CallAnalyzer
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((($function_storage
|
if ($class_storage
|
||||||
&& $function_storage->mutation_free
|
&& $class_storage->mutation_free
|
||||||
&& (!$function_storage instanceof \Psalm\Storage\MethodStorage
|
&& $function_storage
|
||||||
|| !$function_storage->mutation_free_inferred))
|
&& $function_storage->cased_name === '__construct'
|
||||||
|| ($class_storage
|
|
||||||
&& $class_storage->mutation_free))
|
|
||||||
&& !$statements_analyzer->node_data->isPureCompatible($arg->value)
|
|
||||||
&& ($node_type = $statements_analyzer->node_data->getType($arg->value))
|
&& ($node_type = $statements_analyzer->node_data->getType($arg->value))
|
||||||
|
&& !$context->inside_throw
|
||||||
) {
|
) {
|
||||||
foreach ($node_type->getAtomicTypes() as $atomic_arg_type) {
|
foreach ($node_type->getAtomicTypes() as $atomic_arg_type) {
|
||||||
if ($atomic_arg_type instanceof Type\Atomic\TNamedObject) {
|
if ($atomic_arg_type instanceof Type\Atomic\TNamedObject) {
|
||||||
|
@ -24,9 +24,11 @@ class ThrowAnalyzer
|
|||||||
PhpParser\Node\Stmt\Throw_ $stmt,
|
PhpParser\Node\Stmt\Throw_ $stmt,
|
||||||
Context $context
|
Context $context
|
||||||
) {
|
) {
|
||||||
|
$context->inside_throw = true;
|
||||||
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) {
|
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$context->inside_throw = false;
|
||||||
|
|
||||||
if ($context->check_classes
|
if ($context->check_classes
|
||||||
&& ($throw_type = $statements_analyzer->node_data->getType($stmt->expr))
|
&& ($throw_type = $statements_analyzer->node_data->getType($stmt->expr))
|
||||||
|
@ -306,8 +306,19 @@ class ClassTemplateCovarianceTest extends TestCase
|
|||||||
],
|
],
|
||||||
'allowImmutableCovariance' => [
|
'allowImmutableCovariance' => [
|
||||||
'<?php
|
'<?php
|
||||||
|
/**
|
||||||
|
* @psalm-immutable
|
||||||
|
*/
|
||||||
class Animal {}
|
class Animal {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @psalm-immutable
|
||||||
|
*/
|
||||||
class Dog extends Animal{}
|
class Dog extends Animal{}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @psalm-immutable
|
||||||
|
*/
|
||||||
class Cat extends Animal{}
|
class Cat extends Animal{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user