Skip to content

We can not assume the type of Query::getResult() if ResultType may be void #260

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

Merged
merged 1 commit into from
Jan 24, 2022

Conversation

arnaud-lb
Copy link
Contributor

@arnaud-lb arnaud-lb commented Jan 24, 2022

Fixes #259

Normally we assume the type of Query<ResultType>::getResult() to be array<ResultType>. However, we also assume that Query<void>::getResult() returns a int (void denotes an INSERT or DELETE query).

So we can not assume the type of Query<ResultType>::getResult() to be array<ResultType> if there is a chance that ResultType is void.

In this PR I change the DynamicReturnTypeExtension of Query::getResult() so that no return type is assumed when ResultType may be void.

Note:

This has an impact on this feature when used in conjunction with template types, as this is not valid anymore:

/**
 * @template T
 * @param Query<T> $q
 * @return array<T>
 */
function test($q) {
    return $q->getResult(); // mixed
}

However, this is valid:

/**
 * @template T of array|object A non-void type parameter
 * @param Query<T> $q
 * @return array<T>
 */
function test($q) {
    return $q->getResult(); // array<T>
}

@ondrejmirtes
Copy link
Member

Thank you!

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

Successfully merging this pull request may close these issues.

Wrong type inference for QueryBuilder::update and QueryBuilder::delete.
2 participants