Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix param-out generics via stubs #2952

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

Closed
staabm wants to merge 1 commit into phpstan:1.10.x from staabm:param-out
Closed

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Mar 1, 2024

triggered by discussion in ee737e6#commitcomment-138984141

Copy link
Contributor Author

staabm commented Mar 1, 2024
edited
Loading

@rvanvelzen may I ask you for your opinion on these conditional types involved, as I think you are the expert :)?


I am wondering why we resolve @param differently compared to @param-out

$paramType = TypeUtils::resolveLateResolvableTypes(
TemplateTypeHelper::resolveTemplateTypes(
$this->resolveConditionalTypesForParameter($param->getType()),
$this->resolvedTemplateTypeMap,
$this->callSiteVarianceMap,
TemplateTypeVariance::createContravariant(),
),
false,
);

vs.

$paramOutType = $param->getOutType();
if ($paramOutType !== null) {
$paramOutType = TemplateTypeHelper::resolveTemplateTypes(
$paramOutType,
$this->resolvedTemplateTypeMap,
$this->callSiteVarianceMap,
TemplateTypeVariance::createCovariant(),
);
}

harmonizing this does not yet make a difference though, as the conditional types involved are not ConditionalTypeForParameter for param-out. so I am wondering whether phpdoc-parser needs adjustments to produce ConditionalTypeForParameter instead of ConditionalType for param-out...?

Copy link
Contributor

The reason the added tests fail is because anonymous functions don't support phpdocs, so the parameter type is never set correctly.

Why sort etc. didn't work before is because coming from the signature map they're defined as PassedByReference::readsArgument() instead of PassedByReference::createsNewVariable(), so the out-type is never used.

As for the conditional parameters: it probably hasn't been a use-case for now. I didn't implement param-out types 😉

Copy link
Contributor

What was the issue you were trying to use @staabm
rsort seems to handle list/non-empty https://phpstan.org/r/3a1f2bc6-5d8d-4662-937a-f3b10c84fe43
should we close this ?

Also param out seems to support conditional

$this->resolveConditionalTypesForParameter($paramOutType),

Copy link
Contributor Author

staabm commented Oct 28, 2025

@VincentLanglet I think motivation is the comments in ee737e6#commitcomment-138984141

Copy link
Contributor

@VincentLanglet I think motivation is the comments in ee737e6#commitcomment-138984141

Then I think it can be close because the issue is solved for both rsort and custom method with generic conditional param out
https://phpstan.org/r/95c69276-87cf-4a5b-b436-fd571c5b0255

@staabm staabm deleted the param-out branch October 28, 2025 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /