Skip to content

Commit e2b5a60

Browse files
authored
Merge branch refs/heads/1.12.x into 2.1.x
2 parents a54cdb0 + d2e193c commit e2b5a60

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,4 +507,21 @@ public function testReportWrongType(
507507
$this->analyse([__DIR__ . '/data/wrong-var-native-type.php'], $expectedErrors);
508508
}
509509

510+
public function testBug12457(): void
511+
{
512+
$this->checkTypeAgainstNativeType = true;
513+
$this->checkTypeAgainstPhpDocType = true;
514+
$this->strictWideningCheck = true;
515+
$this->analyse([__DIR__ . '/data/bug-12457.php'], [
516+
[
517+
'PHPDoc tag @var with type array{numeric-string} is not subtype of type array{lowercase-string&numeric-string&uppercase-string}.',
518+
13,
519+
],
520+
[
521+
'PHPDoc tag @var with type callable(): string is not subtype of type callable(): numeric-string&lowercase-string&uppercase-string.',
522+
22,
523+
],
524+
]);
525+
}
526+
510527
}
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 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)