@@ -866,6 +866,34 @@ public function specifyTypesInCondition(
866866
867867 $ nullSafeTypes = $ this ->handleDefaultTruthyOrFalseyContext ($ context , $ rootExpr , $ expr , $ scope );
868868 return $ context ->true () ? $ types ->unionWith ($ nullSafeTypes ) : $ types ->normalize ($ scope )->intersectWith ($ nullSafeTypes ->normalize ($ scope ));
869+ } elseif (
870+ $ expr instanceof Expr \New_
871+ && $ expr ->class instanceof Name
872+ && $ this ->reflectionProvider ->hasClass ($ expr ->class ->toString ())
873+ ) {
874+ $ classReflection = $ this ->reflectionProvider ->getClass ($ expr ->class ->toString ());
875+
876+ if ($ classReflection ->hasConstructor ()) {
877+ $ methodReflection = $ classReflection ->getConstructor ();
878+ $ asserts = $ methodReflection ->getAsserts ();
879+
880+ if ($ asserts ->getAll () !== []) {
881+ $ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs ($ scope , $ expr ->getArgs (), $ methodReflection ->getVariants (), $ methodReflection ->getNamedArgumentsVariants ());
882+
883+ $ asserts = $ asserts ->mapTypes (static fn (Type $ type ) => TemplateTypeHelper::resolveTemplateTypes (
884+ $ type ,
885+ $ parametersAcceptor ->getResolvedTemplateTypeMap (),
886+ $ parametersAcceptor instanceof ParametersAcceptorWithPhpDocs ? $ parametersAcceptor ->getCallSiteVarianceMap () : TemplateTypeVarianceMap::createEmpty (),
887+ TemplateTypeVariance::createInvariant (),
888+ ));
889+
890+ $ specifiedTypes = $ this ->specifyTypesFromAsserts ($ context , $ expr , $ asserts , $ parametersAcceptor , $ scope );
891+
892+ if ($ specifiedTypes !== null ) {
893+ return $ specifiedTypes ;
894+ }
895+ }
896+ }
869897 } elseif (!$ context ->null ()) {
870898 return $ this ->handleDefaultTruthyOrFalseyContext ($ context , $ rootExpr , $ expr , $ scope );
871899 }
0 commit comments