Skip to content

Commit 71d2836

Browse files
Traverse typewhen we can contain lowercase/upercase strings
1 parent d06f792 commit 71d2836

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/Type/VerbosityLevel.php

Lines changed: 9 additions & 1 deletion
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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,17 @@ 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+
}
526+
514527
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

0 commit comments

Comments
 (0)