Skip to content

Commit caa0a5b

Browse files
committed
Fix gettype in match
1 parent aa66b84 commit caa0a5b

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/Analyser/TypeSpecifier.php

+3
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ public function specifyTypesInCondition(
226226
}
227227

228228
if ($types !== null) {
229+
if ($leftExpr !== $unwrappedLeftExpr) {
230+
$types = $types->unionWith($this->create($leftExpr, $rightType, $context, false, $scope, $rootExpr));
231+
}
229232
return $types;
230233
}
231234
}

tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,13 @@ public function testBug9457(): void
498498
$this->analyse([__DIR__ . '/data/bug-9457.php'], []);
499499
}
500500

501+
public function testBug8614(): void
502+
{
503+
if (PHP_VERSION_ID < 80100) {
504+
$this->markTestSkipped('Test requires PHP 8.1.');
505+
}
506+
507+
$this->analyse([__DIR__ . '/data/bug-8614.php'], []);
508+
}
509+
501510
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php // lint >= 8.1
2+
3+
namespace Bug8614;
4+
5+
/**
6+
* @param int|float|bool|string|object|mixed[] $value
7+
*/
8+
function stringify(int|float|bool|string|object|array $value): string
9+
{
10+
return match (gettype($value)) {
11+
'integer', 'double', 'boolean', 'string' => (string) $value,
12+
'object', 'array' => var_export($value, true),
13+
};
14+
}

0 commit comments

Comments
 (0)