Skip to content

Allow generators to have a real return type of mixed #5626

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
wants to merge 1 commit into from

Conversation

TysonAndre
Copy link
Contributor

Fixes an edge case overlooked in
#5313

@TysonAndre
Copy link
Contributor Author

The travis build failure was caused by Fixed JIT for SEND_VAR $undefined_cv (the commit already has a comment about the failure), and is unrelated to this.

@@ -1263,7 +1263,8 @@ static void zend_mark_function_as_generator() /* {{{ */

if (CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
zend_type return_type = CG(active_op_array)->arg_info[-1].type;
zend_bool valid_type = (ZEND_TYPE_FULL_MASK(return_type) & MAY_BE_ITERABLE) != 0;
zend_bool valid_type = (ZEND_TYPE_FULL_MASK(return_type) & MAY_BE_ITERABLE) != 0 ||
ZEND_TYPE_FULL_MASK(return_type) == MAY_BE_ANY;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should actually check for & (MAY_BE_ITERATABLE|MAY_BE_OBJECT) != 0. : object is also a fine type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At which point we should really adjust the error message to be generic and not list every single possible type. Something along the lines of...

Cannot use %s as generator return type, because it is not a supertype of Generator

Generator return type must be a supertype of Generator, %s given

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Fixes an edge case overlooked in
php#5313

Generators are objects, so `object` should have also been allowed in addition to
`iterable` and `Traversable`
@kocsismate
Copy link
Member

Thank you, @TysonAndre!

@php-pulls php-pulls closed this in 9b33272 May 26, 2020
@TysonAndre TysonAndre deleted the mixed-generator branch November 25, 2021 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants