Skip to content

Add non regression test for 11056 #3427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,12 @@ public function testNoNamedArguments(): void
]);
}

public function testBug11056(): void
{
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-11056.php'], []);
}

public function testBug11506(): void
{
$this->analyse([__DIR__ . '/data/bug-11506.php'], []);
Expand Down
59 changes: 59 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-11056.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php declare(strict_types = 1);

namespace Bug11056;

interface Item {}
class A implements Item {}
class B implements Item {}
class C implements Item {}

/**
* @template T
* @param class-string<T>|string $class
* @return ($class is class-string<T> ? T : mixed)
*/
function createA(string $class) {
return new $class();
}

/**
* @template T
* @param class-string<T> $class
* @return T
*/
function createB(string $class) {
return new $class();
}

/**
* @param Item[] $values
*/
function receive(array $values): void { }

receive(
array_map(
createA(...),
[ A::class, B::class, C::class ]
)
);

receive(
array_map(
createB(...),
[ A::class, B::class, C::class ]
)
);

receive(
array_map(
static fn($val) => createA($val),
[ A::class, B::class, C::class ]
)
);

receive(
array_map(
static fn($val) => createB($val),
[ A::class, B::class, C::class ]
)
);