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

Calls to magic __invoke() method do not always resolve return type templates #3102

Open
mecha opened this issue Oct 24, 2024 · 0 comments
Open
Labels

Comments

@mecha
Copy link

mecha commented Oct 24, 2024

Describe the bug

When a class __invoke() method is hinted to return a type that includes class-level template types (e.g. @returns T[]), the inferred type for return values will not have the template types resolved to concrete types.

Interestingly, this behavior is not reproducible if:

  1. the return type is just a template type on its own (i.e. @return T),
  2. the __invoke() method is called explicitly on the object.

To Reproduce

/** @template T */
class Bug
{
    /** @param T $value */
    public function __construct($value) {}

    /** @return T[] */
    public function method() {}

    /** @return T[] */
    public function __invoke() {}
}

$bug = new Bug(new DateTime());
// ^ Bug<DateTime>

$value = $bug->method();
// ^ DateTime[]

$value = $bug->__invoke();
// ^ DateTime[]

$value = $bug();
// ^ T[]

Expected behavior

Since the LSP is aware that the object is a Bug, I would also expect the return value's template types to be resolved to concrete types using the invoked object as context (which in this case is Bug<DateTime>).

Platform and version
Arch Linux, kernel v6.10.10
Intelephense v1.12.6 (Neovim)

@bmewburn bmewburn added the bug label Oct 24, 2024
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

2 participants