Skip to content

Commit 5ebaa40

Browse files
committed
fix
1 parent 52980d0 commit 5ebaa40

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/Analyser/Generator/ExprHandler/InterpolatedStringHandler.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
use PHPStan\Analyser\Generator\ExprAnalysisResult;
1313
use PHPStan\Analyser\Generator\ExprHandler;
1414
use PHPStan\Analyser\Generator\GeneratorScope;
15-
use PHPStan\Analyser\Generator\NoopNodeCallback;
1615
use PHPStan\Analyser\SpecifiedTypes;
1716
use PHPStan\DependencyInjection\AutowiredService;
1817
use PHPStan\Reflection\InitializerExprTypeResolver;
18+
use PHPStan\ShouldNotHappenException;
1919
use PHPStan\Type\Constant\ConstantStringType;
2020
use function array_merge;
2121

@@ -46,16 +46,20 @@ public function analyseExpr(
4646
yield from [];
4747

4848
$resultType = null;
49+
$resultNativeType = null;
50+
4951
$hasYield = false;
5052
$throwPoints = [];
5153
$impurePoints = [];
5254
$isAlwaysTerminating = false;
5355
foreach ($expr->parts as $part) {
5456
if ($part instanceof InterpolatedStringPart) {
5557
$partType = new ConstantStringType($part->value);
58+
$partNativeType = $partType;
5659
} else {
57-
$result = yield new ExprAnalysisRequest($stmt, $part, $scope, $context->enterDeep(), new NoopNodeCallback());
60+
$result = yield new ExprAnalysisRequest($stmt, $part, $scope, $context->enterDeep(), $alternativeNodeCallback);
5861
$partType = $result->type->toString();
62+
$partNativeType = $result->nativeType->toString();
5963

6064
$hasYield = $hasYield || $result->hasYield;
6165
$throwPoints = array_merge($throwPoints, $result->throwPoints);
@@ -66,16 +70,21 @@ public function analyseExpr(
6670

6771
if ($resultType === null) {
6872
$resultType = $partType;
73+
$resultNativeType = $partNativeType;
6974
continue;
7075
}
7176

77+
if ($resultNativeType === null) {
78+
throw new ShouldNotHappenException();
79+
}
80+
7281
$resultType = $this->initializerExprTypeResolver->resolveConcatType($resultType, $partType);
82+
$resultNativeType = $this->initializerExprTypeResolver->resolveConcatType($resultNativeType, $partNativeType);
7383
}
7484

75-
$type = $resultType ?? new ConstantStringType('');
7685
return new ExprAnalysisResult(
77-
$type,
78-
$type,
86+
$resultType ?? new ConstantStringType(''),
87+
$resultNativeType ?? new ConstantStringType(''),
7988
$scope,
8089
hasYield: $hasYield,
8190
isAlwaysTerminating: $isAlwaysTerminating,

0 commit comments

Comments
 (0)