From 4ada5555f476439a897e2632bc01512d862d8166 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 19 Jan 2024 20:22:22 +0100 Subject: [PATCH] More tests --- tests/Template/ClassTemplateTest.php | 63 ++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/Template/ClassTemplateTest.php b/tests/Template/ClassTemplateTest.php index 7c34eb33ad6..af2366232fe 100644 --- a/tests/Template/ClassTemplateTest.php +++ b/tests/Template/ClassTemplateTest.php @@ -4265,6 +4265,69 @@ public function enqueue($value): void {} /** @psalm-suppress InvalidArgument */ $a->enqueue("str"); ' + ], + 'testSatisfies2' => [ + 'code' => ' + * + * @param TNewValue $value + * + * @psalm-this-out self<(TValue|TNewValue): satisfied-by> + */ + public function enqueue($value): void {} + + /** @return list */ + public function ret(): array { + return []; + } + } + + /** @param FutureSplQueue $a */ + function take(FutureSplQueue $a): int { + foreach ($a->ret() as $v) { + return $v; + } + return 0; + } + + function takeInt(int $a): int { + return $a; + } + + /** @param 1|2 $a */ + function takeIntExact(int $a): int { + return $a; + } + + /** @var FutureSplQueue */ + $a = new FutureSplQueue; + + /** @psalm-check-type-exact $a = FutureSplQueue */; + + $a->enqueue(1); + + /** @psalm-check-type-exact $a = FutureSplQueue<1: int> */; + + $a->enqueue(2); + + /** @psalm-check-type-exact $a = FutureSplQueue<1|2: int> */; + + foreach ($a->ret() as $v) { + takeInt($v); + takeIntExact($v); + } + + /** @psalm-check-type-exact $a = FutureSplQueue<1|2: int> */; + + take($a); + + /** @psalm-check-type-exact $a = FutureSplQueue */; + ' ] ]; }