@@ -311,7 +311,7 @@ public function normalizeClass(string $class): string
311311}
312312
313313/** @return array{PhpClassReflectionExtension, \PHPStanTurbo\PhpClassReflectionExtension} */
314- $ pcreBuildSides = static function (bool $ infer , int $ memberCacheKeysMax ) use ($ pcreCollaborators ): array {
314+ $ pcreBuildSides = static function (bool $ infer , int $ memberCacheKeysMax, ? \ PHPStan \ Parser \ Parser $ parser = null ) use ($ pcreCollaborators ): array {
315315 $ make = static fn (string $ class ) => new $ class (
316316 scopeFactory: $ pcreCollaborators ['scopeFactory ' ],
317317 phpDocsResolver: $ pcreCollaborators ['phpDocsResolver ' ],
@@ -322,7 +322,7 @@ public function normalizeClass(string $class): string
322322 annotationsMethodsClassReflectionExtension: $ pcreCollaborators ['annotationsMethodsClassReflectionExtension ' ],
323323 annotationsPropertiesClassReflectionExtension: $ pcreCollaborators ['annotationsPropertiesClassReflectionExtension ' ],
324324 signatureMapProvider: $ pcreCollaborators ['signatureMapProvider ' ],
325- parser: $ pcreCollaborators ['parser ' ],
325+ parser: $ parser ?? $ pcreCollaborators ['parser ' ],
326326 stubPhpDocProvider: $ pcreCollaborators ['stubPhpDocProvider ' ],
327327 reflectionProviderProvider: $ pcreCollaborators ['reflectionProviderProvider ' ],
328328 fileTypeMapper: $ pcreCollaborators ['fileTypeMapper ' ],
@@ -533,6 +533,51 @@ public function normalizeClass(string $class): string
533533);
534534// }}}
535535
536+ // {{{ an inference that throws: the twin removes the class's in-process
537+ // marker on the normal return only, so a later ask infers nothing for it
538+ $ pcreThrowObservations = [];
539+ foreach (['php ' , 'native ' ] as $ pcreSide ) {
540+ $ pcreThrowingParser = new class ($ pcreCollaborators ['parser ' ]) implements \PHPStan \Parser \Parser {
541+
542+ public bool $ armed = true ;
543+
544+ public function __construct (private \PHPStan \Parser \Parser $ inner )
545+ {
546+ }
547+
548+ public function parseFile (string $ file ): array
549+ {
550+ if ($ this ->armed ) {
551+ $ this ->armed = false ;
552+ throw new \RuntimeException ('parser failed ' );
553+ }
554+ return $ this ->inner ->parseFile ($ file );
555+ }
556+
557+ public function parseString (string $ sourceCode ): array
558+ {
559+ return $ this ->inner ->parseString ($ sourceCode );
560+ }
561+
562+ };
563+ [$ pcrePhpSide , $ pcreNativeSide ] = $ pcreBuildSides (true , 4096 , $ pcreThrowingParser );
564+ $ pcreExtension = $ pcreSide === 'php ' ? $ pcrePhpSide : $ pcreNativeSide ;
565+ $ pcreThrowClass = $ pcreReflectionProvider ->getClass ('PhpClassReflectionFamilyFixture\FixtureBase ' );
566+ foreach (['first ' , 'second ' ] as $ pcreAttempt ) {
567+ try {
568+ $ pcreThrowObservations [$ pcreSide ][$ pcreAttempt ] = $ pcreDescriber ->describeProperty ($ pcreExtension ->getProperty ($ pcreThrowClass , 'inferredFromConstructor ' , $ pcreScopes ['outOfClass ' ]));
569+ } catch (\Throwable $ e ) {
570+ $ pcreThrowObservations [$ pcreSide ][$ pcreAttempt ] = 'throws ' . $ pcreDescriber ->normalizeClass (get_class ($ e )) . ': ' . $ e ->getMessage ();
571+ }
572+ $ pcreThrowObservations [$ pcreSide ][$ pcreAttempt . ' in process ' ] = (new ReflectionProperty ($ pcreExtension , 'inferClassConstructorPropertyTypesInProcess ' ))->getValue ($ pcreExtension );
573+ }
574+ }
575+ check (
576+ $ pcreThrowObservations ['php ' ] === $ pcreThrowObservations ['native ' ],
577+ 'PhpClassReflectionExtension inference after a throwing one: ' . ($ pcreFirstDifference ($ pcreThrowObservations ['php ' ], $ pcreThrowObservations ['native ' ]) ?? '' ),
578+ );
579+ // }}}
580+
536581if (isset ($ pcreStandalone )) {
537582 echo $ failures === 0 ? "ALL OK \n" : "$ failures failure(s) \n" ;
538583 exit ($ failures === 0 ? 0 : 1 );
0 commit comments