1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #728 - remove statement return type when re-analysing

This commit is contained in:
Matthew Brown 2018-05-09 09:30:23 -04:00
parent 31121cfc6d
commit 318220a1bf
2 changed files with 22 additions and 0 deletions

View File

@ -47,6 +47,8 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
PhpParser\Node\Expr\MethodCall $stmt,
Context $context
) {
$stmt->inferredType = null;
if (ExpressionChecker::analyze($statements_checker, $stmt->var, $context) === false) {
return false;
}

View File

@ -258,6 +258,26 @@ class SwitchTypeTest extends TestCase
}
}',
],
'dontResolveTypesBadly' => [
'<?php
$a = new A;
switch (rand(0,1)) {
case 0:
case 1:
$dt = $a->maybeReturnsDT();
if (!is_null($dt)) {
$dt = $dt->format(\DateTime::ISO8601);
}
break;
}
class A {
public function maybeReturnsDT(): ?\DateTimeInterface {
return rand(0,1) ? new \DateTime("now") : null;
}
}',
],
];
}