Skip to content

Commit f4dedc3

Browse files
committed
Serialization: Bring back shadowing but only after the filtering
Followup fix to #80009. We can still get ambiguities from colliding decls across modules with the deserialization filtering. Bring back calling the general lookup shadowing after the filtering. This way it won't use filtered out decls to hide potential candidates. rdar://148286345
1 parent 2f30161 commit f4dedc3

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
@@ -2766,6 +2766,12 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
27662766
if (M)
27672767
return diagnoseFatal();
27682768

2769+
if (values.size() > 1) {
2770+
// Apply shadowing filtering after other local filters so we don't rule out
2771+
// valid candidates shadowed by invalid ones.
2772+
removeShadowedDecls(values, baseModule);
2773+
}
2774+
27692775
// When all is said and done, we should have a single value here to return.
27702776
if (values.size() != 1) {
27712777
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)