Skip to content

Commit 59adcae

Browse files
authored
Merge pull request #80656 from xymus/deser-late-shadowing-6.2
[6.2] Serialization: Apply type-checking shadowing after deserialization filtering
2 parents ee4b70f + 764cd1f commit 59adcae

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
@@ -2826,6 +2826,12 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
28262826
if (M)
28272827
return diagnoseFatal();
28282828

2829+
if (values.size() > 1) {
2830+
// Apply shadowing filtering after other local filters so we don't rule out
2831+
// valid candidates shadowed by invalid ones.
2832+
removeShadowedDecls(values, baseModule);
2833+
}
2834+
28292835
// When all is said and done, we should have a single value here to return.
28302836
if (values.size() != 1) {
28312837
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)