-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Psalm 4.5 and later ignores assertions of instanceof Interface #5236
Comments
I found these snippets: https://psalm.dev/r/863377401f<?php
function get_header(bool $param = false): ArrayIterator|HeaderInterface
{
if ($param) return new ArrayIterator();
else return new Header();
}
class Header implements HeaderInterface
{
public function doStuff(): void {}
}
interface HeaderInterface
{
public function doStuff(): void;
}
$header = get_header();
assert($header instanceof HeaderInterface);
$header->doStuff();
|
It appears assert removes |
I found these snippets: https://psalm.dev/r/50cf76d7eb<?php
function get_header(bool $param = false): ArrayIterator|HeaderInterface
{
if ($param) return new ArrayIterator();
else return new Header();
}
class Header implements HeaderInterface
{
public function doStuff(): void {}
}
interface HeaderInterface
{
public function doStuff(): void;
}
$header = get_header();
/** @psalm-trace $header */;
assert($header instanceof HeaderInterface);
/** @psalm-trace $header */;
$header->doStuff();
|
@weirdan Should have tried the trace too, thanks for the example! :) Kinda funny regression, assert should have caused |
Simplified: https://psalm.dev/r/84f2bd0e92 |
I found these snippets: https://psalm.dev/r/84f2bd0e92<?php
class SomeClass {}
interface SomeInterface {
public function doStuff(): void;
}
function takesAorB(SomeClass|SomeInterface $some): void {
if ($some instanceof SomeInterface) {
$some->doStuff();
}
}
|
Sorry, this is a pretty bad bug and should have been caught in a test |
Here's an example:
https://psalm.dev/r/863377401f
This worked in 4.4.1
The text was updated successfully, but these errors were encountered: