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
8 changes: 8 additions & 0 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\PropertyHook;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
Expand Down Expand Up @@ -3946,6 +3947,9 @@ public function enterMatch(Expr\Match_ $expr): self
} else {
$cond = $expr->cond;
}
if ($cond instanceof Scalar) {
return $this;
}

$type = $this->getType($cond);
$nativeType = $this->getNativeType($cond);
Expand Down Expand Up @@ -4265,6 +4269,10 @@ private function unsetExpression(Expr $expr): self

public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType, TrinaryLogic $certainty): self
{
if ($expr instanceof Scalar) {
return $this;
}

if ($expr instanceof ConstFetch) {
$loweredConstName = strtolower($expr->name->toString());
if (in_array($loweredConstName, ['true', 'false', 'null'], true)) {
Expand Down
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Debug/DebugScopeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,17 @@ public function testRuleInPhpStanNamespace(): void
]);
}

public function testPr4663(): void
{
$this->analyse([__DIR__ . '/data/pr-4663.php'], [
[
implode("\n", [
"\$result (Yes): 'no matches!'",
"native \$result (Yes): 'no matches!'",
]),
11,
],
]);
}

}
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Debug/data/pr-4663.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types = 1); // lint >= 8.1

namespace PR4663;

use function PHPStan\debugScope;

function (): void {
$result = match(1){
default => 'no matches!'
};
debugScope();
};
Loading