1212use PHPStan \Analyser \Generator \ExprAnalysisResult ;
1313use PHPStan \Analyser \Generator \ExprHandler ;
1414use PHPStan \Analyser \Generator \GeneratorScope ;
15- use PHPStan \Analyser \Generator \NoopNodeCallback ;
1615use PHPStan \Analyser \SpecifiedTypes ;
1716use PHPStan \DependencyInjection \AutowiredService ;
1817use PHPStan \Reflection \InitializerExprTypeResolver ;
18+ use PHPStan \ShouldNotHappenException ;
1919use PHPStan \Type \Constant \ConstantStringType ;
2020use 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