Skip to content

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Aug 8, 2025

Closes phpstan/phpstan#12548

I didn't exactly copy-paste the snippet given because I don't understand how you can expect

/**
     * @template T of object
     *
     * @param T $object
     *
     * @return (T is static ? T : static)
     *
     * @phpstan-assert-if-true =static $object
     */
    public static function assertInstanceOf(object $object)
    {
        if (!$object instanceof static) {
            throw new \Error('Object is not an instance of static class');
        }

        return $object;
    }

to correctly work: phpstan-assert-if-true only work if the method returns a boolean.

Closes phpstan/phpstan#11289
Closes phpstan/phpstan#12376

@ondrejmirtes
Copy link
Member

Aren't both phpstan/phpstan#11289 and phpstan/phpstan#12376 fixed too?

@VincentLanglet VincentLanglet force-pushed the fix/12548 branch 3 times, most recently from aa4e1ba to 944ade1 Compare September 10, 2025 11:51
@VincentLanglet
Copy link
Contributor Author

Aren't both phpstan/phpstan#11289 and phpstan/phpstan#12376 fixed too?

Indeed, I added non regression tests

@ondrejmirtes ondrejmirtes merged commit 19e4658 into phpstan:2.1.x Sep 12, 2025
449 of 456 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants