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

Incorrectly resolved $this return of PHPDoc defined method in mixin context #3556

Closed
SCIF opened this issue Jun 10, 2020 · 5 comments
Closed
Labels

Comments

@SCIF
Copy link
Contributor

SCIF commented Jun 10, 2020

https://psalm.dev/r/fc69f45670

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/fc69f45670
<?php

/**
* @method $this active()
*/
class A {
    public function __call($name, $arguments) {}
}

/**
*
* @mixin A
*/
class B {
}

$b = new B;
/** @psalm-trace $c */
$c = $b->active();
Psalm output (using commit 5617e9d):

ERROR: UndefinedMethod - 19:10 - Method B::active does not exist

INFO: MixedAssignment - 19:1 - Unable to determine the type that $c is being assigned to

INFO: Trace - 19:1 - $c: mixed

INFO: UnusedVariable - 19:1 - Variable $c is never referenced

INFO: MissingParamType - 7:28 - Parameter $name has no provided type

INFO: MissingParamType - 7:35 - Parameter $arguments has no provided type

@SCIF SCIF changed the title Incorrectly resolved $this in mixin context Incorrectly resolved $this return of PHPDoc defined method in mixin context Jun 10, 2020
@SCIF
Copy link
Contributor Author

SCIF commented Jun 10, 2020

That affects phpdoc defined methods only: https://psalm.dev/r/1a255b844f

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/1a255b844f
<?php

/**
* @method $this active()
*/
class A {
    public function __call($name, $arguments) {}
    /** @return $this */
    public function b() {}
}

/**
*
* @mixin A
*/
class B {
}

$b = new B;
/** @psalm-trace $c */
$c = $b->active();
/** @psalm-trace $c */
$c = $b->b();
Psalm output (using commit 5617e9d):

ERROR: UndefinedMethod - 21:10 - Method B::active does not exist

INFO: MixedAssignment - 21:1 - Unable to determine the type that $c is being assigned to

INFO: Trace - 21:1 - $c: mixed

INFO: Trace - 23:1 - $c: B&static

INFO: UnusedVariable - 21:1 - Variable $c is never referenced

INFO: UnusedVariable - 23:1 - Variable $c is never referenced

INFO: MissingParamType - 7:28 - Parameter $name has no provided type

INFO: MissingParamType - 7:35 - Parameter $arguments has no provided type

ERROR: InvalidReturnType - 8:17 - No return statements were found for method A::b but return type 'A' was expected

@orklah orklah added the bug label Oct 24, 2021
robchett added a commit to robchett/psalm that referenced this issue Nov 8, 2023
robchett added a commit to robchett/psalm that referenced this issue Nov 8, 2023
@weirdan
Copy link
Collaborator

weirdan commented Feb 10, 2024

Fixed in #10356 . Note that the class importing the mixin should either have it's own __call() or you need to enable usePhpDocMethodsWithoutMagicCall in psalm.xml

https://psalm.dev/r/3d74f0f8cf

@weirdan weirdan closed this as completed Feb 10, 2024
Copy link

I found these snippets:

https://psalm.dev/r/3d74f0f8cf
<?php

/**
* @method $this active()
*/
class A {
    public function __call(string $name, array $arguments) {}
}

/**
*
* @mixin A
*/
class B {
}

$b = new B;
$_c = $b->active();
/** @psalm-trace $_c */;
Psalm output (using commit 6b27a6d):

INFO: Trace - 19:24 - $_c: B&static

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

No branches or pull requests

3 participants