Skip to content

Commit e3ee899

Browse files
VincentLangletondrejmirtes
authored andcommitted
Fix too early inference
1 parent 6dcda72 commit e3ee899

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

Diff for: src/Analyser/MutatingScope.php

-3
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,6 @@ private function resolveType(string $exprString, Expr $node): Type
11291129
}
11301130

11311131
$resultType = $this->initializerExprTypeResolver->resolveConcatType($resultType, $partType);
1132-
if (count($resultType->getConstantStrings()) === 0) {
1133-
return $resultType;
1134-
}
11351132
}
11361133

11371134
return $resultType ?? new ConstantStringType('');

Diff for: tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -599,4 +599,13 @@ public function testBug9436(): void
599599
$this->analyse([__DIR__ . '/data/bug-9436.php'], []);
600600
}
601601

602+
public function testBug11852(): void
603+
{
604+
if (PHP_VERSION_ID < 80000) {
605+
$this->markTestSkipped('Test requires PHP 8.0.');
606+
}
607+
608+
$this->analyse([__DIR__ . '/data/bug-11852.php'], []);
609+
}
610+
602611
}

Diff for: tests/PHPStan/Rules/Comparison/data/bug-11852.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php // lint >= 8.0
2+
3+
namespace Bug11852;
4+
5+
function sayHello(int $type, string $activity): int
6+
{
7+
return match("$type:$activity") {
8+
'159:Work' => 12,
9+
'159:education' => 19,
10+
11+
default => throw new \InvalidArgumentException("unknown values $type:$activity"),
12+
};
13+
}

0 commit comments

Comments
 (0)