@@ -1889,14 +1889,25 @@ DeclContext *ModuleFile::getLocalDeclContext(LocalDeclContextID DCID) {
1889
1889
}
1890
1890
1891
1891
DeclContext *ModuleFile::getDeclContext (DeclContextID DCID) {
1892
+ auto deserialized = getDeclContextChecked (DCID);
1893
+ if (!deserialized) {
1894
+ fatal (deserialized.takeError ());
1895
+ }
1896
+ return deserialized.get ();
1897
+ }
1898
+
1899
+ Expected<DeclContext *> ModuleFile::getDeclContextChecked (DeclContextID DCID) {
1892
1900
if (!DCID)
1893
1901
return FileContext;
1894
1902
1895
1903
if (Optional<LocalDeclContextID> contextID = DCID.getAsLocalDeclContextID ())
1896
1904
return getLocalDeclContext (contextID.getValue ());
1897
1905
1898
- auto D = getDecl (DCID.getAsDeclID ().getValue ());
1906
+ auto deserialized = getDeclChecked (DCID.getAsDeclID ().getValue ());
1907
+ if (!deserialized)
1908
+ return deserialized.takeError ();
1899
1909
1910
+ auto D = deserialized.get ();
1900
1911
if (auto GTD = dyn_cast<GenericTypeDecl>(D))
1901
1912
return GTD;
1902
1913
if (auto ED = dyn_cast<ExtensionDecl>(D))
@@ -3501,7 +3512,6 @@ class DeclDeserializer {
3501
3512
numConformances, numInherited,
3502
3513
rawInheritedAndDependencyIDs);
3503
3514
3504
- auto DC = MF.getDeclContext (contextID);
3505
3515
if (declOrOffset.isComplete ())
3506
3516
return declOrOffset;
3507
3517
@@ -3515,6 +3525,11 @@ class DeclDeserializer {
3515
3525
}
3516
3526
}
3517
3527
3528
+ auto DCOrError = MF.getDeclContextChecked (contextID);
3529
+ if (!DCOrError)
3530
+ return DCOrError.takeError ();
3531
+ auto DC = DCOrError.get ();
3532
+
3518
3533
auto genericParams = MF.maybeReadGenericParams (DC);
3519
3534
if (declOrOffset.isComplete ())
3520
3535
return declOrOffset;
0 commit comments