Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don’t remove null after magic property fetch
  • Loading branch information
muglug committed May 27, 2019
1 parent e512bc7 commit 5861476
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Expand Up @@ -373,7 +373,8 @@ public static function analyzeInstance(
\Psalm\Internal\Analyzer\Statements\Expression\Call\MethodCallAnalyzer::analyze(
$statements_analyzer,
$fake_method_call,
$context
$context,
false
);

if (!in_array('PossiblyNullReference', $suppressed_issues, true)) {
Expand Down
Expand Up @@ -51,7 +51,8 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
public static function analyze(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Expr\MethodCall $stmt,
Context $context
Context $context,
bool $real_method_call = true
) {
$stmt->inferredType = null;

Expand Down Expand Up @@ -343,6 +344,7 @@ public static function analyze(
&& !$invalid_method_call_types
&& $existent_method_ids
&& ($class_type->from_docblock || $class_type->isNullable())
&& $real_method_call
) {
$keys_to_remove = [];

Expand Down
Expand Up @@ -501,7 +501,8 @@ public static function analyzeInstance(
\Psalm\Internal\Analyzer\Statements\Expression\Call\MethodCallAnalyzer::analyze(
$statements_analyzer,
$fake_method_call,
$context
$context,
false
);

if (!in_array('PossiblyNullReference', $suppressed_issues, true)) {
Expand Down
16 changes: 16 additions & 0 deletions tests/MagicPropertyTest.php
Expand Up @@ -320,6 +320,22 @@ public function __set(string $name, $value)
'assertions' => [],
'error_level' => ['MixedArgument'],
],
'dontAssumeNonNullAfterPossibleMagicFetch' => [
'<?php
class C {
public function __get(string $name) : string {
return "hello";
}
}
function foo(?C $c) : void {
echo $c->foo;
if ($c) {}
}',
'assertions' => [],
'error_level' => ['PossiblyNullPropertyFetch'],
],
'accessInMagicGet' => [
'<?php
class X {
Expand Down

0 comments on commit 5861476

Please sign in to comment.