Skip to content

Commit 388d60e

Browse files
phpstan-botclaude
andcommitted
Address review: deduplicate test file and fix NeverType to be explicit
- Reuse tests/PHPStan/Analyser/nsrt/bug-2572.php in rule test instead of duplicating the file in tests/PHPStan/Rules/Functions/data/ - Use explicit NeverType(true) for empty variadic params so the UnresolvableTypeHelper doesn't treat it as unresolvable - Add staabm's reproducer (value() with Closure|TValue union) as additional test coverage Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ae5b8bf commit 388d60e

4 files changed

Lines changed: 24 additions & 27 deletions

File tree

src/Reflection/GenericParametersAcceptorResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function resolve(array $argTypes, ParametersAcceptor $parametersAc
6363
} elseif ($param->getDefaultValue() !== null) {
6464
$argType = $param->getDefaultValue();
6565
} elseif ($param->isVariadic()) {
66-
$argType = new NeverType();
66+
$argType = new NeverType(true);
6767
} else {
6868
continue;
6969
}

tests/PHPStan/Analyser/nsrt/bug-2572.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,25 @@ function collect($elt, ...$elts) {
2525

2626
assertType("'a'", collect("a"));
2727
assertType("'a'|'b'|'c'", collect("a", "b", "c"));
28+
29+
/**
30+
* @template TValue
31+
* @template TArgs
32+
*
33+
* @param TValue|\Closure(TArgs): TValue $value
34+
* @param TArgs ...$args
35+
* @return TValue
36+
*/
37+
function value($value, ...$args)
38+
{
39+
return $value instanceof \Closure ? $value(...$args) : $value;
40+
}
41+
42+
assertType("'foo'", value('foo'));
43+
assertType("'foo'", value('foo', 42));
44+
assertType('42', value(fn () => 42));
45+
assertType('42', value(function ($foo) {
46+
assertType('true', $foo);
47+
48+
return 42;
49+
}, true));

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2693,7 +2693,7 @@ public function testBug8936(): void
26932693

26942694
public function testBug2572(): void
26952695
{
2696-
$this->analyse([__DIR__ . '/data/bug-2572.php'], []);
2696+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-2572.php'], []);
26972697
}
26982698

26992699
public function testDumpFunctions(): void

tests/PHPStan/Rules/Functions/data/bug-2572.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)