Skip to content

Commit

Permalink
One-part encapsed string is correctly converted to string
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 3, 2023
1 parent 4e35f59 commit dc77608
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ private function resolveType(string $exprString, Expr $node): Type
foreach ($node->parts as $part) {
$partType = $part instanceof EncapsedStringPart
? new ConstantStringType($part->value)
: $this->getType($part);
: $this->getType($part)->toString();
if ($resultType === null) {
$resultType = $partType;

Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2916,7 +2916,7 @@ public function dataBinaryOperations(): array
'"$fooString bar"',
],
[
'*ERROR*',
'non-falsy-string',
'"$std bar"',
],
[
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/pathinfo.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8568.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/DeadCode/data/bug-8620.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8635.php');
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/PHPStan/Analyser/data/bug-8635.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Bug8635;

use function PHPStan\Testing\assertType;

class HelloWorld
{
public function EchoInt(int $value): void
{
assertType('numeric-string', "$value");
}
}

0 comments on commit dc77608

Please sign in to comment.