1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

Fix #3240 - check arguments when class cannot be found

This commit is contained in:
Brown 2020-05-02 22:13:59 -04:00
parent aceaf6c356
commit 618a54ff41
2 changed files with 47 additions and 1 deletions

View File

@ -288,9 +288,25 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
$statements_analyzer->node_data->setType($stmt, $new_type); $statements_analyzer->node_data->setType($stmt, $new_type);
} }
self::checkFunctionArguments(
$statements_analyzer,
$stmt->args,
null,
null,
$context
);
return null; return null;
} }
} else { } else {
self::checkFunctionArguments(
$statements_analyzer,
$stmt->args,
null,
null,
$context
);
return null; return null;
} }
} }
@ -311,6 +327,14 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
if ($context->check_classes) { if ($context->check_classes) {
if ($context->isPhantomClass($fq_class_name)) { if ($context->isPhantomClass($fq_class_name)) {
self::checkFunctionArguments(
$statements_analyzer,
$stmt->args,
null,
null,
$context
);
return null; return null;
} }
@ -323,6 +347,14 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
$statements_analyzer->getSuppressedIssues(), $statements_analyzer->getSuppressedIssues(),
false false
) === false) { ) === false) {
self::checkFunctionArguments(
$statements_analyzer,
$stmt->args,
null,
null,
$context
);
return; return;
} }
@ -543,6 +575,14 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
$stmt_type->reference_free = true; $stmt_type->reference_free = true;
} }
} }
} else {
self::checkFunctionArguments(
$statements_analyzer,
$stmt->args,
null,
null,
$context
);
} }
} }

View File

@ -1100,7 +1100,13 @@ class MethodCallTest extends TestCase
foo(new AChild());', foo(new AChild());',
'error_message' => 'PossiblyNullArgument' 'error_message' => 'PossiblyNullArgument'
] ],
'checkVariableInUnknownClassConstructor' => [
'<?php
/** @psalm-suppress UndefinedClass */
new Missing($class_arg);',
'error_message' => 'PossiblyUndefinedVariable',
],
]; ];
} }
} }