Skip to content

Serialization: Bring back shadowing but only after the filtering #80550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2766,6 +2766,12 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
if (M)
return diagnoseFatal();

if (values.size() > 1) {
// Apply shadowing filtering after other local filters so we don't rule out
// valid candidates shadowed by invalid ones.
removeShadowedDecls(values, baseModule);
}

// When all is said and done, we should have a single value here to return.
if (values.size() != 1) {
return llvm::make_error<XRefError>("result is ambiguous", pathTrace,
Expand Down
50 changes: 50 additions & 0 deletions test/Serialization/shadowed-class-vs-protocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/// Ensure cross references to shadowed decls take into account the shadowing
/// after the custom deserialization filtering.

// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// REQUIRES: objc_interop

// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
// RUN: %t/SwiftLib.swift -I %t -emit-module-path %t/SwiftLib.swiftmodule
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
// RUN: -typecheck %t/Client.swift -I %t

//--- module.modulemap
module RootLib {
header "RootLib.h"
}

module MiddleLib {
header "MiddleLib.h"
export *
}

//--- RootLib.h
__attribute__((swift_name("ShadowedProtocol")))
@protocol Shadowed
@end

//--- MiddleLib.h
@import Foundation;
#include "RootLib.h"

@interface Shadowed: NSObject <Shadowed>
@end

//--- SwiftLib.swift
import MiddleLib

public func funcRef() -> Shadowed { fatalError() }

extension Shadowed {
public func method() -> Shadowed { fatalError() }
}

//--- Client.swift
import SwiftLib

@inlinable
public func bar() {
let _ = funcRef().method()
}