@@ -5787,6 +5787,29 @@ bool CollectionElementContextualFailure::diagnoseAsError() {
5787
5787
}
5788
5788
};
5789
5789
5790
+ if (locator->isForSequenceElementType ()) {
5791
+ auto purpose = FailureDiagnostic::getContextualTypePurpose (getAnchor ());
5792
+ // If this is a conversion failure related to binding of `for-each`
5793
+ // statement it has to be diagnosed as pattern match if there are
5794
+ // holes present in the contextual type.
5795
+ if ((purpose == ContextualTypePurpose::CTP_ForEachStmt ||
5796
+ purpose == ContextualTypePurpose::CTP_ForEachSequence) &&
5797
+ contextualType->hasUnresolvedType ()) {
5798
+ auto diagnostic = emitDiagnostic (
5799
+ (contextualType->is <TupleType>() && !eltType->is <TupleType>())
5800
+ ? diag::cannot_match_expr_tuple_pattern_with_nontuple_value
5801
+ : diag::cannot_match_unresolved_expr_pattern_with_value,
5802
+ eltType);
5803
+ (void )trySequenceSubsequenceFixIts (diagnostic);
5804
+ } else {
5805
+ diagnoseSingleElement (contextualType->isExistentialType ()
5806
+ ? diag::cannot_convert_sequence_element_protocol
5807
+ : diag::cannot_convert_sequence_element_value,
5808
+ eltType, contextualType);
5809
+ }
5810
+ return true ;
5811
+ }
5812
+
5790
5813
auto isFixedToDictionary = [&](ArrayExpr *anchor) {
5791
5814
return llvm::any_of (getSolution ().Fixes , [&](ConstraintFix *fix) {
5792
5815
auto *fixAnchor = getAsExpr<ArrayExpr>(fix->getAnchor ());
@@ -5839,29 +5862,6 @@ bool CollectionElementContextualFailure::diagnoseAsError() {
5839
5862
}
5840
5863
}
5841
5864
5842
- if (locator->isForSequenceElementType ()) {
5843
- auto purpose = FailureDiagnostic::getContextualTypePurpose (getAnchor ());
5844
- // If this is a conversion failure related to binding of `for-each`
5845
- // statement it has to be diagnosed as pattern match if there are
5846
- // holes present in the contextual type.
5847
- if ((purpose == ContextualTypePurpose::CTP_ForEachStmt ||
5848
- purpose == ContextualTypePurpose::CTP_ForEachSequence) &&
5849
- contextualType->hasUnresolvedType ()) {
5850
- auto diagnostic = emitDiagnostic (
5851
- (contextualType->is <TupleType>() && !eltType->is <TupleType>())
5852
- ? diag::cannot_match_expr_tuple_pattern_with_nontuple_value
5853
- : diag::cannot_match_unresolved_expr_pattern_with_value,
5854
- eltType);
5855
- (void )trySequenceSubsequenceFixIts (diagnostic);
5856
- } else {
5857
- diagnoseSingleElement (contextualType->isExistentialType ()
5858
- ? diag::cannot_convert_sequence_element_protocol
5859
- : diag::cannot_convert_sequence_element_value,
5860
- eltType, contextualType);
5861
- }
5862
- return true ;
5863
- }
5864
-
5865
5865
return false ;
5866
5866
}
5867
5867
0 commit comments