Skip to content

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