@@ -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))
@@ -3485,7 +3496,6 @@ class swift::DeclDeserializer {
3485
3496
numConformances, numInherited,
3486
3497
rawInheritedAndDependencyIDs);
3487
3498
3488
- auto DC = MF.getDeclContext (contextID);
3489
3499
if (declOrOffset.isComplete ())
3490
3500
return declOrOffset;
3491
3501
@@ -3499,6 +3509,11 @@ class swift::DeclDeserializer {
3499
3509
}
3500
3510
}
3501
3511
3512
+ auto DCOrError = MF.getDeclContextChecked (contextID);
3513
+ if (!DCOrError)
3514
+ return DCOrError.takeError ();
3515
+ auto DC = DCOrError.get ();
3516
+
3502
3517
auto genericParams = MF.maybeReadGenericParams (DC);
3503
3518
if (declOrOffset.isComplete ())
3504
3519
return declOrOffset;
0 commit comments