-
-
Notifications
You must be signed in to change notification settings - Fork 947
iterable<T> seems to be declared incorrectly #8880
Copy link
Copy link
Closed
Description
Bug report
I came to a conclusion that iterable<T> in PHPStan is declared to be contravariant in its parameter. This is wrong; it should be covariant in it instead.
Code snippet that reproduces the problem
Expected output
This code fails at runtime (we attempt to call putStrLn with an int) but produces no errors during type-checking. The reason is that IProcessor must be contravariant in its parameter T, but PHPStan believes it is covariant in it. It seems that builtin type iterable<T> is mistakingly declared in PHPStan to be contravariant in T. This is wrong: its method current() returns T, and only covariant types can occur in that position. If you change iterable to \Iterator, \Generator, or array in the code, you’ll get a type error, which is the correct behaviour.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels