88use PHPStan \Analyser \Scope ;
99use PHPStan \DependencyInjection \AutowiredParameter ;
1010use PHPStan \DependencyInjection \AutowiredService ;
11+ use PHPStan \Node \DeepNodeCloner ;
1112use PHPStan \Node \Expr \GetOffsetValueTypeExpr ;
1213use PHPStan \PhpDoc \NameScopeAlreadyBeingCreatedException ;
1314use PHPStan \PhpDoc \Tag \VarTag ;
@@ -36,6 +37,7 @@ public function __construct(
3637 private TypeNodeResolver $ typeNodeResolver ,
3738 private FileTypeMapper $ fileTypeMapper ,
3839 private ReflectionProvider $ reflectionProvider ,
40+ private DeepNodeCloner $ deepNodeCloner ,
3941 #[AutowiredParameter(ref: '%reportWrongPhpDocTypeInVarTag% ' )]
4042 private bool $ checkTypeAgainstPhpDocType ,
4143 #[AutowiredParameter(ref: '%reportAnyTypeWideningInVarTag% ' )]
@@ -90,7 +92,7 @@ public function checkVarType(Scope $scope, Node\Expr $var, Node\Expr $expr, arra
9092 public function checkExprType (Scope $ scope , Node \Expr $ expr , Type $ varTagType ): array
9193 {
9294 $ errors = [];
93- $ exprNativeType = $ scope ->getScopeNativeType ( $ expr );
95+ $ exprNativeType = $ scope ->getNativeType ( $ this -> deepNodeCloner -> cloneNode ( $ expr) );
9496 $ containsPhpStanType = $ this ->containsPhpStanType ($ varTagType );
9597 if ($ this ->shouldVarTagTypeBeReported ($ scope , $ expr , $ exprNativeType , $ varTagType )) {
9698 $ verbosity = VerbosityLevel::getRecommendedLevelByType ($ exprNativeType , $ varTagType );
@@ -100,7 +102,7 @@ public function checkExprType(Scope $scope, Node\Expr $expr, Type $varTagType):
100102 $ exprNativeType ->describe ($ verbosity ),
101103 ))->identifier ('varTag.nativeType ' )->build ();
102104 } else {
103- $ exprType = $ scope ->getScopeType ( $ expr );
105+ $ exprType = $ scope ->getType ( $ this -> deepNodeCloner -> cloneNode ( $ expr) );
104106 if (
105107 $ this ->shouldVarTagTypeBeReported ($ scope , $ expr , $ exprType , $ varTagType )
106108 && ($ this ->checkTypeAgainstPhpDocType || $ containsPhpStanType )
@@ -115,7 +117,7 @@ public function checkExprType(Scope $scope, Node\Expr $expr, Type $varTagType):
115117 }
116118
117119 if (count ($ errors ) === 0 && $ containsPhpStanType ) {
118- $ exprType = $ scope ->getScopeType ( $ expr );
120+ $ exprType = $ scope ->getType ( $ this -> deepNodeCloner -> cloneNode ( $ expr) );
119121 if (!$ exprType ->equals ($ varTagType )) {
120122 $ verbosity = VerbosityLevel::getRecommendedLevelByType ($ exprType , $ varTagType );
121123 $ errors [] = RuleErrorBuilder::message (sprintf (
0 commit comments