Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,6 @@ private function resolveType(string $exprString, Expr $node): Type
}

$resultType = $this->initializerExprTypeResolver->resolveConcatType($resultType, $partType);
if (count($resultType->getConstantStrings()) === 0) {
Copy link
Contributor Author

@VincentLanglet VincentLanglet Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will still need to check every part to see if it's a lowercase string.

I'm unsure I should change this to

if (count($resultType->getConstantStrings()) === 0 && $resultType->isLowercaseString()->no()) {

to avoid a similar bug to come back if we introduce another string Accessory.

return $resultType;
}
}

return $resultType ?? new ConstantStringType('');
Expand Down
9 changes: 9 additions & 0 deletions tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,4 +599,13 @@ public function testBug9436(): void
$this->analyse([__DIR__ . '/data/bug-9436.php'], []);
}

public function testBug11852(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0.');
}

$this->analyse([__DIR__ . '/data/bug-11852.php'], []);
}

}
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-11852.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php // lint >= 8.0

namespace Bug11852;

function sayHello(int $type, string $activity): int
{
return match("$type:$activity") {
'159:Work' => 12,
'159:education' => 19,

default => throw new \InvalidArgumentException("unknown values $type:$activity"),
};
}
Loading