Skip to content

Commit f30800c

Browse files
committed
[Serialization] Handle operators that can't be deserialized.
We were already doing this for top-level declarations; just use the same recovery code for operators. More rdar://problem/31920901
1 parent e822910 commit f30800c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,14 @@ void ModuleFile::lookupValue(DeclName name,
13301330
auto iter = OperatorMethodDecls->find(name.getBaseName());
13311331
if (iter != OperatorMethodDecls->end()) {
13321332
for (auto item : *iter) {
1333-
auto VD = cast<ValueDecl>(getDecl(item.second));
1333+
Expected<Decl *> declOrError = getDeclChecked(item.second);
1334+
if (!declOrError) {
1335+
if (!getContext().LangOpts.EnableDeserializationRecovery)
1336+
fatal(declOrError.takeError());
1337+
llvm::consumeError(declOrError.takeError());
1338+
continue;
1339+
}
1340+
auto VD = cast<ValueDecl>(declOrError.get());
13341341
results.push_back(VD);
13351342
}
13361343
}

test/Serialization/Recovery/typedefs-in-enums.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ func use(_: BadEnum) {} // expected-error {{use of undeclared type 'BadEnum'}}
1919
func test() {
2020
_ = producesOkayEnum()
2121
_ = producesBadEnum() // expected-error {{use of unresolved identifier 'producesBadEnum'}}
22+
23+
// Force a lookup of the ==
24+
_ = Optional(OkayEnum.noPayload).map { $0 == .noPayload }
2225
}
2326

2427
#else // TEST
@@ -30,6 +33,10 @@ public enum BadEnum {
3033
case perfectlyOkayPayload(Int)
3134
case problematic(Any, WrappedInt)
3235
case alsoOkay(Any, Any, Any)
36+
37+
static public func ==(a: BadEnum, b: BadEnum) -> Bool {
38+
return false
39+
}
3340
}
3441
// CHECK-LABEL: enum BadEnum {
3542
// CHECK-RECOVERY-NOT: enum BadEnum
@@ -38,16 +45,22 @@ public enum OkayEnum {
3845
case noPayload
3946
case plainOldAlias(Any, UnwrappedInt)
4047
case other(Int)
48+
49+
static public func ==(a: OkayEnum, b: OkayEnum) -> Bool {
50+
return false
51+
}
4152
}
4253
// CHECK-LABEL: enum OkayEnum {
4354
// CHECK-NEXT: case noPayload
4455
// CHECK-NEXT: case plainOldAlias(Any, UnwrappedInt)
4556
// CHECK-NEXT: case other(Int)
57+
// CHECK-NEXT: static func ==(a: OkayEnum, b: OkayEnum) -> Bool
4658
// CHECK-NEXT: }
4759
// CHECK-RECOVERY-LABEL: enum OkayEnum {
4860
// CHECK-RECOVERY-NEXT: case noPayload
4961
// CHECK-RECOVERY-NEXT: case plainOldAlias(Any, Int32)
5062
// CHECK-RECOVERY-NEXT: case other(Int)
63+
// CHECK-RECOVERY-NEXT: static func ==(a: OkayEnum, b: OkayEnum) -> Bool
5164
// CHECK-RECOVERY-NEXT: }
5265

5366
public enum OkayEnumWithSelfRefs {

0 commit comments

Comments
 (0)