@@ -5870,68 +5870,79 @@ static bool hasMissingElseInChain(IfStmt *ifStmt) {
5870
5870
return false ;
5871
5871
}
5872
5872
5873
- void SkipUnhandledConstructInResultBuilderFailure::diagnosePrimary (
5874
- bool asNote) {
5873
+ bool SkipUnhandledConstructInResultBuilderFailure::diagnosePatternBinding (
5874
+ PatternBindingDecl *PB) const {
5875
+ bool diagnosed = false ;
5875
5876
5876
- if (auto *decl = unhandled.dyn_cast <Decl *>()) {
5877
- if (auto *PB = dyn_cast<PatternBindingDecl>(decl)) {
5878
- // Tailored diagnostics for computed properties.
5879
- if (!PB->hasStorage ()) {
5880
- }
5877
+ for (unsigned i : range (PB->getNumPatternEntries ())) {
5878
+ auto *pattern = PB->getPattern (i);
5879
+
5880
+ // Each variable bound by the pattern must be stored.
5881
+ {
5882
+ SmallVector<VarDecl *, 8 > variables;
5883
+ pattern->collectVariables (variables);
5881
5884
5882
- enum class PropertyKind : unsigned { lazy, wrapped, computed };
5885
+ bool diagnosedStorage = false ;
5886
+ for (auto *var : variables)
5887
+ diagnosedStorage |= diagnoseStorage (var);
5888
+
5889
+ // if storage has been diagnosed, let's move to the next entry.
5890
+ if (diagnosedStorage) {
5891
+ diagnosed = true ;
5892
+ continue ;
5893
+ }
5894
+ }
5883
5895
5884
- // Diagnose all of the patterns without explicit initializers.
5885
- bool diagnosed = false ;
5886
- for (unsigned i : range (PB->getNumPatternEntries ())) {
5887
- auto *pattern = PB->getPattern (i);
5896
+ // Diagnose all of the patterns without explicit initializers.
5897
+ if (PB->isExplicitlyInitialized (i))
5898
+ continue ;
5888
5899
5889
- // Each variable bound by the pattern must be stored.
5890
- SmallVector<VarDecl *, 8 > variables;
5891
- pattern->collectVariables (variables);
5900
+ StringRef name;
5892
5901
5893
- for (auto *var : variables) {
5894
- if (var->getImplInfo ().isSimpleStored ())
5895
- continue ;
5902
+ if (auto *TP = dyn_cast<TypedPattern>(pattern)) {
5903
+ if (auto *NP = dyn_cast<NamedPattern>(TP->getSubPattern ()))
5904
+ name = NP->getNameStr ();
5905
+ }
5896
5906
5897
- PropertyKind kind;
5898
- if (var->getAttrs ().hasAttribute <LazyAttr>()) {
5899
- kind = PropertyKind::lazy;
5900
- } else if (var->hasAttachedPropertyWrapper ()) {
5901
- kind = PropertyKind::wrapped;
5902
- } else {
5903
- kind = PropertyKind::computed;
5904
- }
5907
+ emitDiagnosticAt (pattern->getLoc (),
5908
+ diag::result_builder_requires_explicit_var_initialization,
5909
+ !name.empty (), name, builder->getName ())
5910
+ .fixItInsertAfter (pattern->getEndLoc (), " = <#value#>" );
5905
5911
5906
- emitDiagnosticAt (PB->getLoc (),
5907
- diag::cannot_declare_computed_var_in_result_builder,
5908
- static_cast <unsigned >(kind));
5912
+ diagnosed = true ;
5913
+ }
5909
5914
5910
- diagnosed = true ;
5911
- }
5915
+ return diagnosed;
5916
+ }
5912
5917
5913
- if (PB->isExplicitlyInitialized (i))
5914
- continue ;
5918
+ bool SkipUnhandledConstructInResultBuilderFailure::diagnoseStorage (
5919
+ VarDecl *var) const {
5920
+ enum class PropertyKind : unsigned { lazy, wrapped, computed };
5915
5921
5916
- StringRef name;
5922
+ if (var->getImplInfo ().isSimpleStored ())
5923
+ return false ;
5917
5924
5918
- if (auto *TP = dyn_cast<TypedPattern>(pattern)) {
5919
- if (auto *NP = dyn_cast<NamedPattern>(TP->getSubPattern ()))
5920
- name = NP->getNameStr ();
5921
- }
5925
+ PropertyKind kind;
5926
+ if (var->getAttrs ().hasAttribute <LazyAttr>()) {
5927
+ kind = PropertyKind::lazy;
5928
+ } else if (var->hasAttachedPropertyWrapper ()) {
5929
+ kind = PropertyKind::wrapped;
5930
+ } else {
5931
+ kind = PropertyKind::computed;
5932
+ }
5922
5933
5923
- emitDiagnosticAt (
5924
- pattern->getLoc (),
5925
- diag::result_builder_requires_explicit_var_initialization,
5926
- !name.empty (), name, builder->getName ())
5927
- .fixItInsertAfter (pattern->getEndLoc (), " = <#value#>" );
5934
+ emitDiagnosticAt (var, diag::cannot_declare_computed_var_in_result_builder,
5935
+ static_cast <unsigned >(kind));
5936
+ return true ;
5937
+ }
5928
5938
5929
- diagnosed = true ;
5930
- }
5939
+ void SkipUnhandledConstructInResultBuilderFailure::diagnosePrimary (
5940
+ bool asNote) {
5931
5941
5932
- if (diagnosed)
5933
- return ;
5934
- }
5942
+ if (auto *decl = unhandled.dyn_cast <Decl *>()) {
5943
+ auto *PB = dyn_cast<PatternBindingDecl>(decl);
5944
+ if (PB && diagnosePatternBinding (PB))
5945
+ return ;
5935
5946
}
5936
5947
5937
5948
if (auto stmt = unhandled.dyn_cast <Stmt *>()) {
0 commit comments