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

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Mar 1, 2024

triggered by discussion in ee737e6#commitcomment-138984141

@staabm
Copy link
Contributor Author

staabm commented Mar 1, 2024

@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...?

@rvanvelzen
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 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants