Skip to content

Commit 9d090c8

Browse files
committed
Serialization: Recover from errors under loadObjCMethods
The diagnostics about unintended override of Objective-C methods deserializes more decls than strictly necessary. Any of these could trigger a deserialization failure if they rely on missing dependencies. Simply ignore methods failing to deserialize instead of crashing. We could do better here as this logic may ignore methods that are actually colliding. Instead we could put more information in the lookup table to avoid the need for fully deserializing the decl. rdar://138764733
1 parent 3aed095 commit 9d090c8

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,15 @@ void ModuleFile::loadObjCMethods(
712712
continue;
713713

714714
// Deserialize the method and add it to the list.
715+
// Drop methods with errors.
716+
auto funcOrError = getDeclChecked(std::get<2>(result));
717+
if (!funcOrError) {
718+
diagnoseAndConsumeError(funcOrError.takeError());
719+
continue;
720+
}
721+
715722
if (auto func = dyn_cast_or_null<AbstractFunctionDecl>(
716-
getDecl(std::get<2>(result)))) {
723+
funcOrError.get())) {
717724
methods.push_back(func);
718725
}
719726
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/// Recover under diagnoseUnintendedObjCMethodOverrides.
2+
/// rdar://138764733
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: split-file %s %t
6+
// REQUIRES: objc_interop
7+
8+
// RUN: %target-swift-frontend -emit-module %t/HiddenDep.swift -I %t \
9+
// RUN: -o %t/HiddenDep.swiftmodule \
10+
// RUN: -disable-objc-attr-requires-foundation-module
11+
12+
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -I %t \
13+
// RUN: -o %t/Lib.swiftmodule \
14+
// RUN: -swift-version 6 -enable-library-evolution \
15+
// RUN: -disable-objc-attr-requires-foundation-module
16+
17+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
18+
// RUN: -disable-objc-attr-requires-foundation-module
19+
20+
//--- HiddenDep.swift
21+
@objc
22+
public class HiddenType {}
23+
24+
//--- Lib.swift
25+
internal import HiddenDep
26+
27+
@objc public class Redecl {
28+
@objc
29+
func methodWithXref() -> HiddenType { fatalError() }
30+
}
31+
32+
//--- Client.swift
33+
import Lib
34+
35+
extension Redecl {
36+
@objc(methodWithXref)
37+
func methodWithXref_alias() { }
38+
}

0 commit comments

Comments
 (0)