Skip to content

Commit 15cb7e2

Browse files
phpstan-botclaude
andcommitted
Add regression tests for phpstan/phpstan#7704 and phpstan/phpstan#9360
Both issues report the same underlying bug: unresolvable template type errors when calling functions with variadic template parameters without providing any variadic arguments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 388d60e commit 15cb7e2

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug7704;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @template T
9+
* @template TRest
10+
*
11+
* @param T $first
12+
* @param TRest ...$rest
13+
*
14+
* @return T|TRest
15+
*/
16+
function intersection($first, ...$rest)
17+
{
18+
$ret = $first;
19+
foreach ($rest as $item) {
20+
if (rand(0, 1)) {
21+
$ret = $item;
22+
}
23+
}
24+
return $ret;
25+
}
26+
27+
assertType("'a'", intersection("a"));
28+
assertType("'a'|'b'|'c'", intersection("a", "b", "c"));
29+
assertType('1', intersection(1));
30+
assertType('1|2|3', intersection(1, 2, 3));
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug9360;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @template T of string|bool
9+
*
10+
* @param T ...$args
11+
*
12+
* @return (T is string ? string : bool)
13+
*/
14+
function environment(string|bool ...$args): string|bool
15+
{
16+
if (count($args) === 0) {
17+
return true;
18+
}
19+
return (string) $args[0];
20+
}
21+
22+
assertType('string', environment());
23+
assertType('string', environment('APP_ENV'));
24+
assertType('string', environment('APP_ENV', 'production'));

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,6 +2696,16 @@ public function testBug2572(): void
26962696
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-2572.php'], []);
26972697
}
26982698

2699+
public function testBug7704(): void
2700+
{
2701+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-7704.php'], []);
2702+
}
2703+
2704+
public function testBug9360(): void
2705+
{
2706+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-9360.php'], []);
2707+
}
2708+
26992709
public function testDumpFunctions(): void
27002710
{
27012711
$this->analyse([__DIR__ . '/data/dump-functions.php'], [

0 commit comments

Comments
 (0)