Skip to content

Commit a97585c

Browse files
committed
[Sema] Fix compiler crash when pattern matching optional enum
TypeCheckPattern was able to take the path checking if `Optional.None` should be renamed to lowercase `Optional.none` and if this wasn't necessary still failed but without generating a diagnostic. Now it always provides a diagnostic when failing. This fixes SR-2057.
1 parent 5164668 commit a97585c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,8 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
14531453
/*special kind*/0, Rename.str())
14541454
.fixItReplace(EEP->getLoc(), Rename.str());
14551455

1456+
return true;
14561457
}
1457-
return true;
14581458
}
14591459

14601460
diagnose(EEP->getLoc(), diag::enum_element_pattern_member_not_found,

test/Constraints/patterns.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,13 @@ func ugly(_ a: A<EE>) {
222222
}
223223
}
224224
}
225+
226+
// SR-2057
227+
228+
enum SR2057 {
229+
case foo
230+
}
231+
232+
let sr2057: SR2057? = nil
233+
if case .foo = sr2057 { } // expected-error{{enum case 'foo' not found in type 'SR2057?'}}
234+

0 commit comments

Comments
 (0)