@@ -856,43 +856,30 @@ CaptureInfo ParamCaptureInfoRequest::evaluate(Evaluator &evaluator,
856856 return finder.getCaptureInfo ();
857857}
858858
859- static bool isLazy (PatternBindingDecl *PBD) {
860- if (auto var = PBD->getSingleVar ())
861- return var->getAttrs ().hasAttribute <LazyAttr>();
862- return false ;
863- }
864-
865- void TypeChecker::checkPatternBindingCaptures (IterableDeclContext *DC) {
866- for (auto member : DC->getMembers ()) {
867- // Ignore everything other than PBDs.
868- auto *PBD = dyn_cast<PatternBindingDecl>(member);
869- if (!PBD) continue ;
870- // Walk the initializers for all properties declared in the type with
871- // an initializer.
872- for (unsigned i : range (PBD->getNumPatternEntries ())) {
873- if (PBD->isInitializerSubsumed (i))
874- continue ;
859+ CaptureInfo PatternBindingCaptureInfoRequest::evaluate (Evaluator &evaluator,
860+ PatternBindingDecl *PBD,
861+ unsigned int idx) const {
862+ auto *init = PBD->getExecutableInit (idx);
863+ if (!init)
864+ return CaptureInfo::empty ();
875865
876- auto *init = PBD->getInit (i);
877- if (init == nullptr )
878- continue ;
866+ // Only have captures when we have a PatternBindingInitializer context, i.e
867+ // local variables don't have captures.
868+ auto *DC = PBD->getInitContext (idx);
869+ if (!DC)
870+ return CaptureInfo::empty ();
879871
880- auto *DC = PBD->getInitContext (i);
881- FindCapturedVars finder (init->getLoc (),
882- DC,
883- /* NoEscape=*/ false ,
884- /* ObjC=*/ false ,
885- /* IsGenericFunction*/ false );
886- init->walk (finder);
887-
888- auto &ctx = DC->getASTContext ();
889- if (finder.getDynamicSelfCaptureLoc ().isValid () && !isLazy (PBD)) {
890- ctx.Diags .diagnose (finder.getDynamicSelfCaptureLoc (),
891- diag::dynamic_self_stored_property_init);
892- }
872+ FindCapturedVars finder (init->getLoc (), DC,
873+ /* NoEscape=*/ false ,
874+ /* ObjC=*/ false ,
875+ /* IsGenericFunction*/ false );
876+ init->walk (finder);
893877
894- auto captures = finder.getCaptureInfo ();
895- PBD->setCaptureInfo (i, captures);
896- }
878+ auto &ctx = DC->getASTContext ();
879+ if (finder.getDynamicSelfCaptureLoc ().isValid ()) {
880+ ctx.Diags .diagnose (finder.getDynamicSelfCaptureLoc (),
881+ diag::dynamic_self_stored_property_init);
897882 }
883+
884+ return finder.getCaptureInfo ();
898885}
0 commit comments