Skip to content

Conversation

@gdejong
Copy link
Contributor

@gdejong gdejong commented Nov 26, 2020

Found this when running Psalm in a project of mine that is using reactphp/child-process.

Possibly undesired iteration over regular object React\Stream\ReadableStreamInterface

for the code:

foreach ($this->process->pipes as $pipe) {

The docblock now better reflects the fact that $pipes is an array of either ReadableStreamInterface or WritableStreamInterface.

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

@gdejong Thanks for spotting, the existing definition is indeed incorrect! 👍

It looks like this should be array<ReadableStreamInterface|WritableStreamInterface> instead of ReadableStreamInterface[]|WritableStreamInterface[].

This subtle different means it can contain a mix of both readable and writable streams, instead of an array of either just readable or just writable streams.

@clue clue added this to the v0.6.2 milestone Nov 26, 2020
@gdejong
Copy link
Contributor Author

gdejong commented Nov 26, 2020

Good catch! I'll update the PR!

Found this when running Psalm in a project of mine that is using reactphp/child-process.
```
Possibly undesired iteration over regular object React\Stream\ReadableStreamInterface
```
for the code:
```
foreach ($this->process->pipes as $pipe) {
```

The docblock now better reflects the fact that `$pipes` is an array of either `ReadableStreamInterface` or `WritableStreamInterface`.
@gdejong
Copy link
Contributor Author

gdejong commented Nov 26, 2020

Updated (amended to the same commit).

Unfortunately the current version of PHPStorm (2020.2) does not understand this syntax yet. Psalm support should be available in 2020.3 though.

For now it means that code like \React\ChildProcess\Process::close has no autocomplete.
image

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

@gdejong Thanks for the update, the changes LGTM! :shipit:

If static analysis and IDE autocompletion is an issue, you can always add an additional assert($pipe instanceof ReadableStreamInterface || $pipe instanceof WritableStreamInterface) in front of the respective method call.

@clue clue requested review from WyriHaximus and jsor November 27, 2020 18:53
Copy link
Member

@WyriHaximus WyriHaximus left a comment

Choose a reason for hiding this comment

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

Nice catch, thank you 👍

@WyriHaximus WyriHaximus merged commit 437e00c into reactphp:master Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants