From dc77608ee9ab22e352cd3df60ce2bc2d8d135abc Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Tue, 3 Jan 2023 11:37:48 +0100 Subject: [PATCH] One-part encapsed string is correctly converted to string --- src/Analyser/MutatingScope.php | 2 +- .../Analyser/LegacyNodeScopeResolverTest.php | 2 +- tests/PHPStan/Analyser/NodeScopeResolverTest.php | 1 + tests/PHPStan/Analyser/data/bug-8635.php | 13 +++++++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/PHPStan/Analyser/data/bug-8635.php diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 8dcdda47f8..fcbe29f293 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -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; diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index 9bbabf4886..d2ecfb4f3f 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -2916,7 +2916,7 @@ public function dataBinaryOperations(): array '"$fooString bar"', ], [ - '*ERROR*', + 'non-falsy-string', '"$std bar"', ], [ diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index e5d593210c..2f59cc4816 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -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'); } /** diff --git a/tests/PHPStan/Analyser/data/bug-8635.php b/tests/PHPStan/Analyser/data/bug-8635.php new file mode 100644 index 0000000000..1895254579 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-8635.php @@ -0,0 +1,13 @@ +