Skip to content

Conversation

azjezz
Copy link
Contributor

@azjezz azjezz commented May 30, 2025

closes #11458

}
}

$local_return_type = $generator_return_type;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the actual fix for #11458 which replaces the return type being compared against with TReturn from a generator, or with mixed if the current return type is not a generator.

Comment on lines +9 to +10
public const ERROR_LEVEL = 4;
public const SHORTCODE = 284;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure if those values are correct.

@azjezz
Copy link
Contributor Author

azjezz commented May 30, 2025

Error: src/Psalm/Type/UnionTrait.php:950:21: PossiblyUnusedMethod: Cannot find any calls to method Psalm\Type\Union::isGenerator (see https://psalm.dev/087)

Is it safe to remove isGenerator from UnionTrait? a plugin could be depending on it..

Comment on lines +1179 to +1182
/**
* @return Generator<int,int>
* @psalm-suppress MixedReturnStatement
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the MixedReturnStatement is correct, yield 1 results in mixed, which is returned. previously psalm did not check return statements for generators, so this was never triggered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could make sense to not report MixedReturnStatement here actually, we do that in mago, the reason is the return type of the function is not mixed but rather TReturn on the Generator type is, so it might be a good idea to either not report it, or have a different error code that tells user to have a better TReturn for the generator other than mixed 🤔

Comment on lines +1193 to +1196
/**
* @return Generator<int,int, mixed, mixed>
* @psalm-suppress MixedReturnStatement
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here

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.

incorrect InvalidReturnStatement when returning from an iterable generator.
1 participant