Skip to content

Commit

Permalink
Fix impossible isset checks
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 15, 2020
1 parent c3edbdb commit 4a03c4a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ private static function analyzeAtomicCall(

case Type\Atomic\TTemplateParam::class:
case Type\Atomic\TEmptyMixed::class:
case Type\Atomic\TEmpty::class:
case Type\Atomic\TMixed::class:
case Type\Atomic\TNonEmptyMixed::class:
case Type\Atomic\TObject::class:
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Internal/Type/NegatedAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public static function reconcile(
}
}

return Type::getEmpty();
return $existing_var_type->from_docblock
? Type::getNull()
: Type::getEmpty();
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions tests/TypeReconciliation/IssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,32 @@ public function foo() : ?string {
function foo(C $c) : void {
new DateTime($c->foo() ?? "");
}',
],
'methodCallAfterIsset' => [
'<?php
class B {
public function bar() : void {}
}
/** @psalm-suppress MissingConstructor */
class A {
/** @var B */
public $foo;
public function init() : void {
if (isset($this->foo)) {
return;
}
if (rand(0, 1)) {
$this->foo = new B;
} else {
$this->foo = new B;
}
$this->foo->bar();
}
}'
],
];
Expand Down

0 comments on commit 4a03c4a

Please sign in to comment.