@@ -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))
@@ -3496,7 +3507,6 @@ class swift::DeclDeserializer {
3496
3507
numConformances, numInherited,
3497
3508
rawInheritedAndDependencyIDs);
3498
3509
3499
- auto DC = MF.getDeclContext (contextID);
3500
3510
if (declOrOffset.isComplete ())
3501
3511
return declOrOffset;
3502
3512
@@ -3510,6 +3520,11 @@ class swift::DeclDeserializer {
3510
3520
}
3511
3521
}
3512
3522
3523
+ auto DCOrError = MF.getDeclContextChecked (contextID);
3524
+ if (!DCOrError)
3525
+ return DCOrError.takeError ();
3526
+ auto DC = DCOrError.get ();
3527
+
3513
3528
auto genericParams = MF.maybeReadGenericParams (DC);
3514
3529
if (declOrOffset.isComplete ())
3515
3530
return declOrOffset;
0 commit comments