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

$tmp_parent_var pollutes context #7556

Closed
AndrolGenhald opened this issue Feb 1, 2022 · 3 comments
Closed

$tmp_parent_var pollutes context #7556

AndrolGenhald opened this issue Feb 1, 2022 · 3 comments

Comments

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Feb 1, 2022

@vincent4vx re #7414
https://psalm.dev/r/49d35dd90e
Looks like the same applies to $tmp_mixin_var, so that can probably be fixed at the same time in the same manner.

It would also be a good idea to use $__tmp_parent_var__, with underscores like MatchAnalyzer and ArrayMapReturnTypeProvider so that it's less likely to collide with an actual variable.

It also doesn't work with static, but that's a separate issue.

@psalm-github-bot
Copy link

psalm-github-bot bot commented Feb 1, 2022

I found these snippets:

https://psalm.dev/r/49d35dd90e
<?php

/**
 * @method baz(): Foo
 */
class Foo
{
    public function __call()
    {
        return new self();
    }
}

class Bar extends Foo
{
    public function baz(): Foo
    {
        parent::baz();
        return $tmp_parent_var; // What's this doing here???
    }
}
Psalm output (using commit 2e01e9b):

No issues!
https://psalm.dev/r/e3c3120f6c
<?php

/**
 * @template T
 */
class Foo
{
    public function foobar(): void {}
}

/**
 * @template T
 * @mixin Foo<T>
 */
class Bar
{
    public function baz(): self
    {
        self::foobar();
        return $tmp_mixin_var; // What's this doing here???
    }
}
Psalm output (using commit 2e01e9b):

No issues!
https://psalm.dev/r/65b4820537
<?php

/**
 * @method static baz(): self
 */
class Foo
{
    public static function __callStatic()
    {
        return new self();
    }
}

class Bar extends Foo
{
    public static function baz(): Foo
    {
        return parent::baz();
    }
}
Psalm output (using commit 2e01e9b):

ERROR: TooManyArguments - 18:16 - Too many arguments for Foo::__callStatic - expecting 0 but saw 2

INFO: MixedReturnStatement - 18:16 - Could not infer a return type

INFO: MixedInferredReturnType - 16:35 - Could not verify return type 'Bar' for Bar::baz

@vincent4vx
Copy link
Contributor

vincent4vx commented Feb 2, 2022

I'll do that 😉

But for the third error, it's seems that psalm do not support syntax @method static method(): returnType. When declaring return type before the method name it works : https://psalm.dev/r/8d800f5e5d
It's also the phpstan's behavior.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/8d800f5e5d
<?php

/**
 * @method static self baz()
 */
class Foo
{
    public static function __callStatic()
    {
        return new self();
    }
}

class Bar extends Foo
{
    public static function baz(): Foo
    {
        return parent::baz();
    }
}
Psalm output (using commit 2e01e9b):

No issues!

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

No branches or pull requests

2 participants