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