1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

doc --> dog (#3330)

This commit is contained in:
feek 2020-05-10 08:19:54 -07:00 committed by GitHub
parent 55222573ea
commit a83a6cf3f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -330,7 +330,7 @@ function takesDogList(Collection $dog_collection) : void {
}
```
That last call `addAnimal($doc_collection)` breaks the type of the collection suddenly a collection of dogs becomes a collection of dogs _or_ cats. That is bad.
That last call `addAnimal($dog_collection)` breaks the type of the collection suddenly a collection of dogs becomes a collection of dogs _or_ cats. That is bad.
To prevent this, Psalm emits an error when calling `addAnimal($dog_collection)` saying "addAnimal expects a `Collection<Animal>`, but `Collection<Dog>` was passed". If you haven't encountered this rule before it's probably confusing to you any function that accepted an `Animal` would be happy to accept a subtype thereof. But as we see in the example above, doing so can lead to problems.