Skip to content
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-this-out doesn't work on __construct() #9649

Closed
fluffycondor opened this issue Apr 13, 2023 · 1 comment · Fixed by #10690
Closed

@psalm-this-out doesn't work on __construct() #9649

fluffycondor opened this issue Apr 13, 2023 · 1 comment · Fixed by #10690

Comments

@fluffycondor
Copy link
Contributor

https://psalm.dev/r/2c2d54f466

Expected: no errors.
Got: IfThisIsMismatch.

As a result, now I have to typehint the object manually:
https://psalm.dev/r/6d5e4476ea

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/2c2d54f466
<?php
/**
 * @template T of string
 */
final class App
{
    /** @psalm-this-out self<"idle"> */
    public function __construct() {}

    /**
      * @psalm-if-this-is self<"idle">
      * @psalm-this-out self<"started">
    */
    public function start(): void {}
}

$app = new App();
$app->start();
Psalm output (using commit 71bb951):

ERROR: IfThisIsMismatch - 18:7 - Class type must be App<'idle'> current type App<string>
https://psalm.dev/r/6d5e4476ea
<?php
/**
 * @template T of string
 */
final class App
{
    /**
      * @psalm-if-this-is self<"idle">
      * @psalm-this-out self<"started">
    */
    public function start(): void {}
}

/** @var App<'idle'> */
$app = new App();
$app->start();
Psalm output (using commit 71bb951):

No issues!

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

Successfully merging a pull request may close this issue.

2 participants