-
Notifications
You must be signed in to change notification settings - Fork 667
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
Generic parameter does not accept a union of generics #6073
Comments
Hey @azjezz, can you reproduce the issue on https://psalm.dev ? |
Simplified to https://psalm.dev/r/86a60c6f13 |
I found these snippets: https://psalm.dev/r/86a60c6f13<?php
/**
* @template T
* @param Container<T> $_p
*/
function acceptsContainer($_p): void {
}
/** @param Container<int>|Container<string> $var */
function ff($var): void {
acceptsContainer($var);
}
/**
* @template T
*/
interface Container {}
/**
* @template T
* @param T $_p
* @return Container<T>
* @psalm-suppress InvalidReturnType
*/
function makeContainer($_p): Container {}
|
InvalidArgument
error
@muglug any idea what could be wrong here? It looks like Psalm breaks union apart into constituent types and believes each of them is an upper (?) bound for |
Yeah, have a look at this: https://psalm.dev/r/bbef3b2bdb If there's one type for |
I found these snippets: https://psalm.dev/r/bbef3b2bdb<?php
/**
* @template T
* @param Container<T> $p
* @return Container<T>
*/
function acceptsContainer($p): Container {
return $p;
}
/**
* @param Container<int>|Container<string> $var
* @return Container<int|string>
*/
function ff($var): Container {
return acceptsContainer($var);
}
/**
* @template T
*/
interface Container {}
/**
* @template T
* @param T $_p
* @return Container<T>
* @psalm-suppress InvalidReturnType
*/
function makeContainer($_p): Container {}
|
PHPStan emits a slightly different but comparable error: https://phpstan.org/r/b1097877-6b2c-4f5b-b897-30a0b069bad4 |
The new system for capturing generic constrains introduced in acc7ee2 breaks PSL build.
see: https://github.com/azjezz/psl/runs/3041183878?check_suite_focus=true
I couldn't make a smaller repro 🤔
The text was updated successfully, but these errors were encountered: