Skip to content

Commit ce0178f

Browse files
authored
Merge pull request swiftlang#23357 from theblixguy/fix/SR-10108
[Sema] Fix a crash when attempting to synthesise raw representable conformance
2 parents e325b55 + 146f705 commit ce0178f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Sema/DerivedConformanceRawRepresentable.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,11 @@ static bool canSynthesizeRawRepresentable(DerivedConformance &derived) {
501501
// - the enum elements all have the same type
502502
// - they all match the enum type
503503
for (auto elt : enumDecl->getAllElements()) {
504+
// We cannot synthesize raw representable conformance for an enum with
505+
// cases that have a payload.
506+
if (elt->hasAssociatedValues())
507+
return false;
508+
504509
tc.validateDecl(elt);
505510
if (elt->isInvalid()) {
506511
return false;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
3+
// Just make sure we don't crash.
4+
5+
enum Crash: String {
6+
case foo
7+
case bar(String)
8+
9+
static let shared = Crash()
10+
}
11+
12+
extension Crash {
13+
init() { self = .foo }
14+
}

0 commit comments

Comments
 (0)