@@ -81,11 +81,9 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
8181 {
8282 $ parametersAcceptor = null ;
8383 $ constructorReflection = null ;
84- $ className = null ;
8584 $ classReflection = null ;
8685 $ hasYield = false ;
8786 $ throwPoints = [];
88- $ deferConstructorThrowPoints = false ;
8987 $ impurePoints = [];
9088 $ isAlwaysTerminating = false ;
9189 $ normalizedExpr = $ expr ;
@@ -94,7 +92,6 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
9492
9593 [$ constructorReflection , $ classReflection , $ parametersAcceptor , $ constructorImpurePoints ] = $ this ->processConstructorReflection ($ className , $ expr , $ scope );
9694 $ impurePoints = array_merge ($ impurePoints , $ constructorImpurePoints );
97- $ deferConstructorThrowPoints = true ;
9895
9996 if ($ parametersAcceptor !== null ) {
10097 $ normalizedExpr = ArgumentsNormalizer::reorderNewArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
@@ -139,19 +136,13 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
139136 }
140137 } else {
141138 $ nodeScopeResolver ->processStmtNode ($ expr ->class , $ scope , $ storage , $ nodeCallback , StatementContext::createTopLevel ());
142- $ declaringClass = $ constructorReflection ->getDeclaringClass ();
143- $ constructorThrowPoint = $ this ->getConstructorThrowPoint ($ constructorReflection , $ parametersAcceptor , $ classReflection , $ expr , new Name \FullyQualified ($ declaringClass ->getName ()), $ expr ->getArgs (), $ scope );
144- if ($ constructorThrowPoint !== null ) {
145- $ throwPoints [] = $ constructorThrowPoint ;
146- }
147-
148139 if (!$ constructorReflection ->hasSideEffects ()->no ()) {
149140 $ certain = $ constructorReflection ->isPure ()->no ();
150141 $ impurePoints [] = new ImpurePoint (
151142 $ scope ,
152143 $ expr ,
153144 'new ' ,
154- sprintf ('instantiation of class %s ' , $ declaringClass ->getDisplayName ()),
145+ sprintf ('instantiation of class %s ' , $ constructorReflection -> getDeclaringClass () ->getDisplayName ()),
155146 $ certain ,
156147 );
157148 }
@@ -181,9 +172,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
181172 if ($ className !== null ) {
182173 [$ constructorReflection , $ classReflection , $ parametersAcceptor , $ constructorImpurePoints ] = $ this ->processConstructorReflection ($ className , $ expr , $ scope );
183174 $ impurePoints = array_merge ($ impurePoints , $ constructorImpurePoints );
184- $ deferConstructorThrowPoints = true ;
185175 } else {
186- $ throwPoints [] = InternalThrowPoint::createImplicit ($ scope , $ expr );
187176 $ impurePoints [] = new ImpurePoint (
188177 $ scope ,
189178 $ expr ,
@@ -205,15 +194,14 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
205194 $ impurePoints = array_merge ($ impurePoints , $ argsResult ->getImpurePoints ());
206195 $ isAlwaysTerminating = $ isAlwaysTerminating || $ argsResult ->isAlwaysTerminating ();
207196
208- if ($ deferConstructorThrowPoints && $ className !== null ) {
209- if ($ constructorReflection !== null && $ parametersAcceptor !== null && $ classReflection !== null ) {
210- $ constructorThrowPoint = $ this ->getConstructorThrowPoint ($ constructorReflection , $ parametersAcceptor , $ classReflection , $ expr , new Name \FullyQualified ($ className ), $ expr ->getArgs (), $ scope );
211- if ($ constructorThrowPoint !== null ) {
212- $ throwPoints [] = $ constructorThrowPoint ;
213- }
214- } elseif ($ classReflection === null ) {
215- $ throwPoints [] = InternalThrowPoint::createImplicit ($ scope , $ expr );
197+ if ($ constructorReflection !== null && $ parametersAcceptor !== null ) {
198+ $ className ??= $ constructorReflection ->getDeclaringClass ()->getName ();
199+ $ constructorThrowPoint = $ this ->getConstructorThrowPoint ($ constructorReflection , $ parametersAcceptor , $ expr , new Name \FullyQualified ($ className ), $ expr ->getArgs (), $ scope );
200+ if ($ constructorThrowPoint !== null ) {
201+ $ throwPoints [] = $ constructorThrowPoint ;
216202 }
203+ } elseif ($ classReflection === null ) {
204+ $ throwPoints [] = InternalThrowPoint::createImplicit ($ scope , $ expr );
217205 }
218206
219207 return new ExpressionResult (
@@ -275,7 +263,7 @@ private function processConstructorReflection(string $className, New_ $expr, Mut
275263 /**
276264 * @param list<Node\Arg> $args
277265 */
278- private function getConstructorThrowPoint (MethodReflection $ constructorReflection , ParametersAcceptor $ parametersAcceptor , ClassReflection $ classReflection , New_ $ new , Name $ className , array $ args , MutatingScope $ scope ): ?InternalThrowPoint
266+ private function getConstructorThrowPoint (MethodReflection $ constructorReflection , ParametersAcceptor $ parametersAcceptor , New_ $ new , Name $ className , array $ args , MutatingScope $ scope ): ?InternalThrowPoint
279267 {
280268 $ methodCall = new StaticCall ($ className , $ constructorReflection ->getName (), $ args );
281269 $ normalizedMethodCall = ArgumentsNormalizer::reorderStaticCallArguments ($ parametersAcceptor , $ methodCall );
@@ -300,7 +288,7 @@ private function getConstructorThrowPoint(MethodReflection $constructorReflectio
300288 return InternalThrowPoint::createExplicit ($ scope , $ throwType , $ new , true );
301289 }
302290 } elseif ($ this ->implicitThrows ) {
303- if (!$ classReflection ->is (Throwable::class)) {
291+ if (!$ constructorReflection -> getDeclaringClass () ->is (Throwable::class)) {
304292 return InternalThrowPoint::createImplicit ($ scope , $ methodCall );
305293 }
306294 }
0 commit comments