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

Template params not allowing extending other template params #7795

Open
ricardoboss opened this issue Mar 16, 2022 · 3 comments
Open

Template params not allowing extending other template params #7795

ricardoboss opened this issue Mar 16, 2022 · 3 comments

Comments

@ricardoboss
Copy link
Contributor

I would expect the following to work:

https://psalm.dev/r/0d2844a23d

Is this a supported use case?

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/0d2844a23d
<?php

/**
 * @template T of object
 * @template U of T
 */
class A {
    /**
     * @param U $o
     */
    public function dump(object $o): void
    {
        print_r($o);
    }
}

interface B {}
interface C extends B {}

class D implements C {}

$d = new D();

/** @var A<B, C> */
$a = new A();
$a->dump($d);
Psalm output (using commit a9f4148):

ERROR: InvalidTemplateParam - 25:1 - Extended template param U of A<B, C> expects type T:A as object, type C given

@AndrolGenhald
Copy link
Collaborator

Using a template as a template constraint is pretty broken right now, see also #7764 and #7549.

@castletheperson
Copy link

castletheperson commented Dec 30, 2024

This appears to be fixed now. When I open the snippet in the first comment, running Psalm from the current commit (765dcbf) produces "No Issues!"

Which version was this fixed in? I'm dealing with the same issue in version 5.13.1

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

No branches or pull requests

3 participants