Skip to content

Commit 9d0d521

Browse files
committed
[Diagnostics] Diagnose associated value pattern matching errors separately
from missing function call errors in `ContextualFailure`. It doesn't make sense to diagnose pattern matching errors inside of `diagnoseMissingFunctionCall`, and the code I added to bail out if there is no explicit function expression broke the pattern matching diagnostics anyway.
1 parent dc10f60 commit 9d0d521

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,6 +2243,9 @@ bool ContextualFailure::diagnoseAsError() {
22432243
if (diagnoseMissingFunctionCall())
22442244
return true;
22452245

2246+
if (diagnoseExtraneousAssociatedValues())
2247+
return true;
2248+
22462249
// Special case of some common conversions involving Swift.String
22472250
// indexes, catching cases where people attempt to index them with an integer.
22482251
if (isIntegerToStringIndexConversion()) {
@@ -2662,8 +2665,15 @@ bool ContextualFailure::diagnoseMissingFunctionCall() const {
26622665
!TypeChecker::isConvertibleTo(srcFT->getResult(), toType, getDC()))
26632666
return false;
26642667

2665-
// Diagnose cases where the pattern tried to match associated values but
2666-
// the case we found had none.
2668+
emitDiagnostic(diag::missing_nullary_call, srcFT->getResult())
2669+
.highlight(getSourceRange())
2670+
.fixItInsertAfter(getSourceRange().End, "()");
2671+
2672+
tryComputedPropertyFixIts();
2673+
return true;
2674+
}
2675+
2676+
bool ContextualFailure::diagnoseExtraneousAssociatedValues() const {
26672677
if (auto match =
26682678
getLocator()->getLastElementAs<LocatorPathElt::PatternMatch>()) {
26692679
if (auto enumElementPattern =
@@ -2678,12 +2688,7 @@ bool ContextualFailure::diagnoseMissingFunctionCall() const {
26782688
}
26792689
}
26802690

2681-
emitDiagnostic(diag::missing_nullary_call, srcFT->getResult())
2682-
.highlight(getSourceRange())
2683-
.fixItInsertAfter(getSourceRange().End, "()");
2684-
2685-
tryComputedPropertyFixIts();
2686-
return true;
2691+
return false;
26872692
}
26882693

26892694
bool ContextualFailure::diagnoseCoercionToUnrelatedType() const {

lib/Sema/CSDiagnostics.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,10 @@ class ContextualFailure : public FailureDiagnostic {
637637
/// then we probably meant to call the value.
638638
bool diagnoseMissingFunctionCall() const;
639639

640+
/// Diagnose cases where a pattern tried to match associated values but
641+
/// the enum case had none.
642+
bool diagnoseExtraneousAssociatedValues() const;
643+
640644
/// Produce a specialized diagnostic if this is an invalid conversion to Bool.
641645
bool diagnoseConversionToBool() const;
642646

0 commit comments

Comments
 (0)