Skip to content

Commit 614c81e

Browse files
authored
Fix param-type specification interfering with root-expression types
1 parent ffc0495 commit 614c81e

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,9 @@ private function specifyTypesForConstantStringBinaryExpression(
10991099
}
11001100

11011101
if ($type !== null) {
1102-
return $this->create($exprNode->getArgs()[0]->value, $type, $context, false, $scope, $rootExpr);
1102+
$callType = $this->create($exprNode, $constantType, $context, false, $scope, $rootExpr);
1103+
$argType = $this->create($exprNode->getArgs()[0]->value, $type, $context, false, $scope, $rootExpr);
1104+
return $callType->unionWith($argType);
11031105
}
11041106
}
11051107

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,7 @@ public function dataFileAsserts(): iterable
12561256
yield from $this->gatherAssertTypes(__DIR__ . '/data/extract.php');
12571257
yield from $this->gatherAssertTypes(__DIR__ . '/data/image-size.php');
12581258
yield from $this->gatherAssertTypes(__DIR__ . '/data/base64_decode.php');
1259+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9404.php');
12591260
}
12601261

12611262
/**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Bug9404;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function foo(int|string $x): void
8+
{
9+
if (gettype($x) === 'integer') {
10+
assertType("'integer'", gettype($x));
11+
}
12+
}

0 commit comments

Comments
 (0)