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

Intersection types not working in generics #7496

Open
danog opened this issue Jan 27, 2022 · 2 comments
Open

Intersection types not working in generics #7496

danog opened this issue Jan 27, 2022 · 2 comments

Comments

@danog
Copy link
Collaborator

danog commented Jan 27, 2022

https://psalm.dev/r/542b1e4b94

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/542b1e4b94
<?php
interface a {}

class b {
    public function custom(): int {
        return 0;
    }
}

class c extends b implements a {}

/**
 * @template T as (a&b)
 */
class d {
    /**
     * @param T $param
     */
    public function test(b $param): void {
        echo $param->custom();
    }
}

/** @extends d<c> */
class e extends d {
}
Psalm output (using commit 9168cef):

ERROR: PossiblyUndefinedMethod - 20:22 - Method a::custom does not exist

INFO: MixedArgument - 20:14 - Argument 1 of echo cannot be mixed, expecting string

@wooky
Copy link

wooky commented Jun 2, 2023

Specifically, only the first type of an intersection is considered, with the rest being discarded. So in this case, if we write @template T as (b&a), there would be no issues, but then a's methods would be unresolved.

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