Skip to content
Permalink
Browse files

Fix #2386 - make generator params invariant

  • Loading branch information
muglug committed Nov 29, 2019
1 parent e2d1eca commit a4e18f9b5ee9e47e257b49c440b7586ccada02c1
Showing with 29 additions and 4 deletions.
  1. +4 −4 src/Psalm/Internal/Stubs/CoreGenericClasses.php
  2. +25 −0 tests/Template/ClassTemplateCovarianceTest.php
@@ -86,10 +86,10 @@ public function rewind();
}
/**
* @template-covariant TKey
* @template-covariant TValue
* @template-covariant TSend
* @template-covariant TReturn
* @template TKey
* @template TValue
* @template TSend
* @template TReturn
*
* @template-implements Traversable<TKey, TValue>
*/
@@ -429,6 +429,31 @@ function takesMyArrayOfAChild(MyArray $m) : void {
}',
'error_message' => 'MixedArgumentTypeCoercion',
],
'preventGeneratorVariance' => [
'<?php
class Foo {
function a(): void {}
}
class Bar extends Foo {
function b(): void {}
}
/** @return Generator<int,Bar,Bar,mixed> */
function gen() {
$bar = yield new Bar();
$bar->b();
}
/** @param Generator<int,Foo,Foo,mixed> $gen */
function sendFoo($gen): void {
$gen->send(new Foo());
}
$gen = gen();
sendFoo($gen);',
'error_message' => 'InvalidArgument',
],
];
}
}

0 comments on commit a4e18f9

Please sign in to comment.
You can’t perform that action at this time.