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

Type bounds for generic parameters #10981

Open
vkurdin opened this issue May 18, 2024 · 1 comment
Open

Type bounds for generic parameters #10981

vkurdin opened this issue May 18, 2024 · 1 comment

Comments

@vkurdin
Copy link

vkurdin commented May 18, 2024

How can I fix Bar::foo from this example https://psalm.dev/r/2ec8af4c04 ?

In Scala I can introduce a lower type bound for a new type parameter A1 with lower bound of A: https://scastie.scala-lang.org/3gSkZWZZTnep7lhyzExsZw

More details here https://docs.scala-lang.org/tour/lower-type-bounds.html

Copy link

I found these snippets:

https://psalm.dev/r/2ec8af4c04
<?php

/**
 * @template-covariant A
 */
class Bar
{
    /**
     * @param A $a
     */
    public function foo($a): void
    {
    }
    
    /**
     * @template A1
     * @template-bound A1 >: A # A is a lower bound for A1
     * @param A1 $a
     */
    public function foo2($a): void
    {
    }
}
Psalm output (using commit 16b24bd):

ERROR: InvalidTemplateParam - 9:15 - Template param A of Bar is marked covariant and cannot be used here

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

1 participant