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

Fix param-out generics via stubs #2952

Draft
wants to merge 1 commit into
base: 1.10.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/PHPStan/Analyser/data/param-out.php
Expand Up @@ -501,3 +501,34 @@ function ($s, $t): void {
assertType('string', $s);
assertType('string', $t);
};

// typed via phpdoc in stub file
function rsort(array &$array, int $flags = SORT_REGULAR): bool
{
}

function ($a): void {
\ParamOut\rsort($a);
assertType('list<mixed>', $a);
};
/**
* @param string[] $a
*/
function ($a): void {
\ParamOut\rsort($a);
assertType('list<string>', $a);
};
/**
* @param non-empty-array<string> $a
*/
function ($a): void {
\ParamOut\rsort($a);
assertType('non-empty-list<string>', $a);
};
/**
* @param non-empty-list<string> $a
*/
function ($a): void {
\ParamOut\rsort($a);
assertType('non-empty-list<string>', $a);
};
11 changes: 11 additions & 0 deletions tests/PHPStan/Analyser/param-out.stub
Expand Up @@ -18,4 +18,15 @@ namespace ParamOut {
{
}
}

/**
* @template T
* @template TArray as array<T>
*
* @param TArray $array
* @param-out (TArray is non-empty-array ? non-empty-list<T> : list<T>) $array
*/
function rsort(array &$array, int $flags = SORT_REGULAR): bool
{
}
}