Skip to content

Commit 52ebd4a

Browse files
authored
Merge pull request #80550 from xymus/deser-late-shadowing
Serialization: Bring back shadowing but only after the filtering
2 parents 5e2f20b + f4dedc3 commit 52ebd4a

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,12 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
28242824
if (M)
28252825
return diagnoseFatal();
28262826

2827+
if (values.size() > 1) {
2828+
// Apply shadowing filtering after other local filters so we don't rule out
2829+
// valid candidates shadowed by invalid ones.
2830+
removeShadowedDecls(values, baseModule);
2831+
}
2832+
28272833
// When all is said and done, we should have a single value here to return.
28282834
if (values.size() != 1) {
28292835
return llvm::make_error<XRefError>("result is ambiguous", pathTrace,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/// Ensure cross references to shadowed decls take into account the shadowing
2+
/// after the custom deserialization filtering.
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: split-file %s %t
6+
// REQUIRES: objc_interop
7+
8+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
9+
// RUN: %t/SwiftLib.swift -I %t -emit-module-path %t/SwiftLib.swiftmodule
10+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
11+
// RUN: -typecheck %t/Client.swift -I %t
12+
13+
//--- module.modulemap
14+
module RootLib {
15+
header "RootLib.h"
16+
}
17+
18+
module MiddleLib {
19+
header "MiddleLib.h"
20+
export *
21+
}
22+
23+
//--- RootLib.h
24+
__attribute__((swift_name("ShadowedProtocol")))
25+
@protocol Shadowed
26+
@end
27+
28+
//--- MiddleLib.h
29+
@import Foundation;
30+
#include "RootLib.h"
31+
32+
@interface Shadowed: NSObject <Shadowed>
33+
@end
34+
35+
//--- SwiftLib.swift
36+
import MiddleLib
37+
38+
public func funcRef() -> Shadowed { fatalError() }
39+
40+
extension Shadowed {
41+
public func method() -> Shadowed { fatalError() }
42+
}
43+
44+
//--- Client.swift
45+
import SwiftLib
46+
47+
@inlinable
48+
public func bar() {
49+
let _ = funcRef().method()
50+
}

0 commit comments

Comments
 (0)