Skip to content

Commit bed3414

Browse files
phpstan-botclaude
andcommitted
Add tests for maybe isSuperTypeOf path in ConditionalType::isResolvable()
Mutation testing showed the `$isSuperType->no()` branch was not specifically covered. Added: - NSRT test with a multi-template conditional return type where premature resolution (incorrectly treating `maybe` as resolvable) would collapse `non-empty-list` to `list` - Rule test data for `maybe` cases (T of string|int with target string) verifying no false "unresolvable type" errors are reported Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 092cba3 commit bed3414

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,20 @@ function testNotFullyNarrowable(mixed $a): void
5151
{
5252
assertType('string|T of int (function Bug11894Nsrt\testNotFullyNarrowable(), argument)', conditionalReturn($a));
5353
}
54+
55+
abstract class ConditionalArrayKeys
56+
{
57+
/**
58+
* @template TKey of array-key
59+
* @template TArray of array<TKey, mixed>
60+
* @param TArray $array
61+
* @return (TArray is non-empty-array ? non-empty-list<TKey> : list<TKey>)
62+
*/
63+
abstract public function arrayKeys(array $array): array;
64+
65+
/** @param non-empty-array<int, int> $nonEmpty */
66+
public function testMaybeStaysUnresolved(array $nonEmpty): void
67+
{
68+
assertType('non-empty-list<int>', $this->arrayKeys($nonEmpty));
69+
}
70+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ function testNoRelation(mixed $a): mixed
6868

6969
return conditionalReturn($a);
7070
}
71+
72+
/**
73+
* @template T of string|int
74+
* @param T $a
75+
*/
76+
function testMaybeRelation(mixed $a): mixed
77+
{
78+
return conditionalReturn($a);
79+
}

tests/PHPStan/Rules/Methods/data/bug-11894.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,23 @@ public function testStaticMethod(mixed $a): mixed
5959

6060
return Converter::conditionalReturnStatic($a);
6161
}
62+
63+
/**
64+
* @template T of string|int
65+
* @param T $a
66+
*/
67+
public function testMaybeMethod(mixed $a): mixed
68+
{
69+
$c = new Converter();
70+
return $c->conditionalReturn($a);
71+
}
72+
73+
/**
74+
* @template T of string|int
75+
* @param T $a
76+
*/
77+
public function testMaybeStaticMethod(mixed $a): mixed
78+
{
79+
return Converter::conditionalReturnStatic($a);
80+
}
6281
}

0 commit comments

Comments
 (0)