Skip to content

Commit d2e193c

Browse files
VerbosityLevel - Keep traversing type when we can contain lowercase/upercase strings
1 parent d06f792 commit d2e193c

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/Type/VerbosityLevel.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,18 @@ public static function getRecommendedLevelByType(Type $acceptingType, ?Type $acc
9191
$moreVerboseCallback = static function (Type $type, callable $traverse) use (&$moreVerbose, &$veryVerbose): Type {
9292
if ($type->isCallable()->yes()) {
9393
$moreVerbose = true;
94-
return $type;
94+
95+
// Keep checking if we need to be very verbose.
96+
return $traverse($type);
9597
}
9698
if ($type->isConstantValue()->yes() && $type->isNull()->no()) {
9799
$moreVerbose = true;
100+
101+
// For ConstantArrayType we need to keep checking if we need to be very verbose.
102+
if (!$type->isArray()->no()) {
103+
return $traverse($type);
104+
}
105+
98106
return $type;
99107
}
100108
if (

tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,21 @@ public function testReportWrongType(
511511
$this->analyse([__DIR__ . '/data/wrong-var-native-type.php'], $expectedErrors);
512512
}
513513

514+
public function testBug12457(): void
515+
{
516+
$this->checkTypeAgainstNativeType = true;
517+
$this->checkTypeAgainstPhpDocType = true;
518+
$this->strictWideningCheck = true;
519+
$this->analyse([__DIR__ . '/data/bug-12457.php'], [
520+
[
521+
'PHPDoc tag @var with type array{numeric-string} is not subtype of type array{lowercase-string&numeric-string&uppercase-string}.',
522+
13,
523+
],
524+
[
525+
'PHPDoc tag @var with type callable(): string is not subtype of type callable(): numeric-string&lowercase-string&uppercase-string.',
526+
22,
527+
],
528+
]);
529+
}
530+
514531
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12457;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @param array{numeric-string&uppercase-string&lowercase-string} $a
9+
*/
10+
public function sayHello(array $a): void
11+
{
12+
/** @var array{numeric-string} $b */
13+
$b = $a;
14+
}
15+
16+
/**
17+
* @param callable(): numeric-string&uppercase-string&lowercase-string $a
18+
*/
19+
public function sayHello2(callable $a): void
20+
{
21+
/** @var callable(): string $b */
22+
$b = $a;
23+
}
24+
}

0 commit comments

Comments
 (0)