Skip to content

Commit dc77608

Browse files
committed
One-part encapsed string is correctly converted to string
1 parent 4e35f59 commit dc77608

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/Analyser/MutatingScope.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ private function resolveType(string $exprString, Expr $node): Type
10921092
foreach ($node->parts as $part) {
10931093
$partType = $part instanceof EncapsedStringPart
10941094
? new ConstantStringType($part->value)
1095-
: $this->getType($part);
1095+
: $this->getType($part)->toString();
10961096
if ($resultType === null) {
10971097
$resultType = $partType;
10981098

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,7 @@ public function dataBinaryOperations(): array
29162916
'"$fooString bar"',
29172917
],
29182918
[
2919-
'*ERROR*',
2919+
'non-falsy-string',
29202920
'"$std bar"',
29212921
],
29222922
[

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,7 @@ public function dataFileAsserts(): iterable
11561156
yield from $this->gatherAssertTypes(__DIR__ . '/data/pathinfo.php');
11571157
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8568.php');
11581158
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/DeadCode/data/bug-8620.php');
1159+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8635.php');
11591160
}
11601161

11611162
/**
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Bug8635;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
public function EchoInt(int $value): void
10+
{
11+
assertType('numeric-string', "$value");
12+
}
13+
}

0 commit comments

Comments
 (0)